go get github.com/bluzelle/blzgo
package main
import (
"github.com/bluzelle/blzgo"
"log"
)
func main() {
// create client
options := &bluzelle.Options{
Mnemonic: "...",
Endpoint: "http://dev.testnet.public.bluzelle.com:1317",
UUID: "...",
}
client, err := bluzelle.NewClient(options)
if err != nil {
log.Fatalf("%s", err)
}
key := "foo"
value := "bar"
gasInfo := bluzelle.GasInfo{
MaxFee: 4000001,
}
leaseInfo := bluzelle.LeaseInfo{
Days: 1,
}
// create key
if err := client.Create(key, value, gasInfo, leaseInfo); err != nil {
log.Fatalf("%s", err)
} else {
log.Printf("create key success: true\n")
}
// read key
if v, err := client.Read(key); err != nil {
log.Fatalf("%s", err)
} else {
log.Printf("read key success: %t\n", v == value)
}
// update key
if err := client.Create(key, value, gasInfo, nil); err != nil {
log.Fatalf("%s", err)
} else {
log.Printf("create key success: true\n")
}
// delete key
if err := client.Delete(key, gasInfo); err != nil {
log.Fatalf("%s", err)
} else {
log.Printf("delete key success: true\n")
}
}