A simple object persistance inferface for golang.
go 1.13.x
Prequisite: add json tags to any objects you want to store.
type Bob {
Name string `json:"name"` // in our examples this will be the primary key
Height int `json:"height"`
}
import "github.com/ace-teknologi/memzy/dynamodb"
...
c := dynamodb.New("BOB_STORAGE")
The memory client is good for testing.
import "github.com/ace-teknologi/memzy/memory"
...
c := memory.New("name")
Generally I don't use the above clients directly. Instead I use the interface which enables me to switch implementations in testing.
import (
"os"
"github.com/ace-teknologi/memzy"
"github.com/ace-teknologi/memzy/dynamodb"
"github.com/ace-teknologi/memzy/memory"
)
var memzyClient memzy.memzy
func init() {
if os.Getenv == "PRODUCTION" {
memzyClient = dynamodb.New("BOB_STORAGE")
} else {
memzyClient = memory.New("name")
}
}
var rdj Bob
memzyClient.GetItem(rdj, map[string]interface{}{"Name": "Robert Downey Jr."})
fmt.Printf("Robert Downey Jr is %d cm tall", rdj.Height) // Robery Downey Jr. is 173 cm tall
var rnm = &Bob{
Name: "Robert Nesta Marley, OM",
Height: 170,
}
memzyClient.PutItem(rnm)
This has basically no features, just the ability to iterate over everything you have stored.
iter := memzyClient.NewIter()
// do stuff
Warning: the API of this pre-1.0 library is unstable. It is recommended to use dependency management.