import ( "context" "github.com/coreos/etcd/clientv3" ) func main() { cli, err := clientv3.NewFromURL("http://localhost:2379") if err != nil { panic(err) } defer cli.Close() // Set the key-value pair ctx := context.Background() if _, err := cli.Put(ctx, "key", "value"); err != nil { panic(err) } // Retrieve the value of the key if resp, err := cli.Get(ctx, "key"); err != nil { panic(err) } else { for _, ev := range resp.Kvs { fmt.Println(string(ev.Key), string(ev.Value)) } } }
import ( "context" "fmt" "github.com/coreos/etcd/clientv3" ) func main() { cli, err := clientv3.NewFromURL("http://localhost:2379") if err != nil { panic(err) } defer cli.Close() // Watch the key for changes ctx := context.Background() rch := cli.Watch(ctx, "key") for wresp := range rch { for _, ev := range wresp.Events { fmt.Printf("%s %q : %q\n", ev.Type, ev.Kv.Key, ev.Kv.Value) } } }In both examples, we can see that the package library used is `github.com/coreos/etcd/clientv3`.