import ( "github.com/docker/libkv/store" "github.com/docker/libkv/store/etcd" ) func main() { etcd.Register() // Register the Etcd store with libkv client, err := store.New([]string{"localhost:2379"}, &store.Config{ Bucket: "test", }) value, err := client.Get("key1") if err != nil { panic(err) } fmt.Println(string(value.Value)) }
import ( "github.com/docker/libkv/store" "github.com/docker/libkv/store/consul" ) func main() { consul.Register() // Register the Consul store with libkv client, err := store.New([]string{"localhost:8500"}, &store.Config{}) ch := make(chan *store.KVPair) _, err = client.Watch("key1", ch) if err != nil { panic(err) } for { kv := <-ch fmt.Printf("Key: %s, Value: %s\n", kv.Key, string(kv.Value)) } }In these examples, we used the Store package to interact with the Etcd and Consul stores. We first registered the store type with the package using its Register() function. We then created a new client instance and used its functions to perform operations on keys and values. Overall, the Store package is a useful library for working with different key-value stores in a simple and consistent way.