Skip to content

Instantly share code, notes, and snippets.

View affix's full-sized avatar
:shipit:
Code never lies, Comments might though

Keiran Smith affix

:shipit:
Code never lies, Comments might though
View GitHub Profile
package main
import (
"bytes"
"fmt"
"log"
"github.com/google/gopacket"
"github.com/google/gopacket/pcap"
)
affix@target:~$ id
uid=1001(affix) gid=1001(affix) groups=1001(affix),999(docker)
@affix
affix / handler.go
Created January 22, 2020 21:11
XML to JSON in Go the full code
package function
import (
"encoding/json"
"encoding/xml"
"fmt"
"io/ioutil"
"log"
"net/http"
)
@affix
affix / handler.go
Created January 22, 2020 21:02
XML to JSON in Go Marshal to JSON
func Handle(req []byte) string {
json, _ := json.Marshal(data.Channel.Posts) // Encode our Struct as JSON
return fmt.Sprintf("%s", string(json)) // Return a String to the OpenFaaS Gateway
}
@affix
affix / handler.go
Created January 22, 2020 20:59
XML to JSON in Go Parse XML
func Handle(req []byte) string {
// ...
data := &PostData{} // Create and initialise a data variable as a PostData struct
err = xml.Unmarshal(body, data) // Parse the XML into the structure
}
@affix
affix / handler.go
Created January 22, 2020 20:52
XML to JSON in Go the PostData Structure
type PostData struct {
Channel struct {
Posts []struct {
Title string `xml:"title"`
Link string `xml:"link"`
Category []string `xml:"category"`
Creator string `xml:"creator"`
PubDate string `xml:"pubDate"`
Updated string `xml:"updated"`
License string `xml:"license"`
@affix
affix / handler.go
Last active January 22, 2020 20:31
XML to JSON in GoLang Demystified getting the feed
func Handle(req []byte) string {
resp, err := http.Get("https://medium.com/feed/@" + string(req)) // Use the 'req' variable to build our feed URL
// Standard Error Handler
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close() // Defer closing until the Handle function returns
body, _ := ioutil.ReadAll(resp.Body) // Read the response body and ignore errors
@affix
affix / handler.go
Created January 22, 2020 20:24
XML to JSON in GoLang Demystified imports
import (
"encoding/json"
"encoding/xml"
"fmt"
"io/ioutil"
"log"
"net/http"
)
@affix
affix / kubectl-updatedotoken.rb
Last active June 9, 2019 12:50
Automatically Update your kubernetes config with the DigitalOcean API and Ruby
#!/usr/bin/env ruby
# DO Kubernetes Config Auto Updater
# Automatically Update your kubeconf using the DigitalOcean api
#
# Get $50 DigitalOcean Credit :: https://m.do.co/c/d755c35183a9
#
# (c) 2019 Keiran Smith <opensource_at_keiran_dot_scot>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@affix
affix / affix-cloud
Created August 18, 2018 09:27
OpenFaaS Cloud affix customers
affix
alexellis