srv := etcdserver.NewServer(cfg)
resp, err := srv.Get(context.Background(), []byte("foo")) if err != nil { // handle error } fmt.Println(string(resp.Kvs[0].Value))
wg := &sync.WaitGroup{} watcher := srv.Watch(context.Background(), []byte("foo")) wg.Add(1) go func() { defer wg.Done() for { select { case wg ==<- watcher.C(): fmt.Println("foo was modified") } } }()This code sets up a watcher on the "foo" key using the server instance's Watch method. When the value associated with "foo" changes, the watcher's channel will be notified and the associated goroutine will print a message. The main goroutine waits for the watcher to finish using a WaitGroup. Overall, the EtcdServer package provides a powerful API for building distributed systems that rely on a consistent and highly-available key-value store.