Skip to content

Instantly share code, notes, and snippets.

@simondrake
simondrake / gkms.go
Created October 14, 2020 17:00
Example of how to encrypt and decrypt GKMS in Go
package main
import (
"context"
"encoding/base64"
"fmt"
"log"
kms "cloud.google.com/go/kms/apiv1"
kmspb "google.golang.org/genproto/googleapis/cloud/kms/v1"
@simondrake
simondrake / builder.go
Created October 1, 2020 10:57
Quick example demonstrating the builder pattern in Go to handle different Cloud providers
package publisher
type Store interface {
Publish(item map[string]interface{}) (string,error)
}
type StoreBuilder struct {
// Registry holds a map of string (Cloud provider) and Store
registry map[string]Store
}
@simondrake
simondrake / main.go
Last active September 15, 2020 14:41
Quick example showing how slices work in Go, and shows how "slicing a slice" can still reference the same underlying Array..
package main
import (
"fmt"
)
func main() {
// len(a)=0, cap(a)=3
a := make([]int, 3, 3)
@simondrake
simondrake / sortSlice.go
Created July 2, 2020 16:05
When passing slices through as a function argument, you're actually passing through a slice header which can have unintended consequences/side-effects.
package main
import (
"fmt"
"sort"
)
func sortItems(items []int) []int {
sortFunc := func(i int, j int) bool {