package main
import (
"fmt"
"go.etcd.io/etcd/Godeps/_workspace/src/golang.org/x/net/context"
"go.etcd.io/etcd/clientv3"
"time"
)
func main() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: []string{"127.0.0.1:2379"},
DialTimeout: time.Second * 5,
})
if err != nil {
fmt.Printf("connect to faild,err:%v", err)
return
}
defer cli.Close()
rch := cli.Watch(context.Background(), "zl")
for wresp := range rch {
for _, ev := range wresp.Events {
fmt.Printf("type:%s key:%s value:%s\n", ev.Type, ev.Kv.Key, ev.Kv.Value)
}
}
}
标签:cli,err,示例,fmt,watch,etcd,go,ev From: https://www.cnblogs.com/z1an/p/17596345.html