|
|
il y a 9 ans | |
|---|---|---|
| .. | ||
| concurrency | il y a 9 ans | |
| integration | il y a 9 ans | |
| mirror | il y a 9 ans | |
| README.md | il y a 9 ans | |
| client.go | il y a 9 ans | |
| client_test.go | il y a 10 ans | |
| cluster.go | il y a 10 ans | |
| compare.go | il y a 10 ans | |
| doc.go | il y a 9 ans | |
| example_cluster_test.go | il y a 9 ans | |
| example_kv_test.go | il y a 9 ans | |
| example_lease_test.go | il y a 9 ans | |
| example_test.go | il y a 9 ans | |
| example_watch_test.go | il y a 9 ans | |
| kv.go | il y a 9 ans | |
| lease.go | il y a 9 ans | |
| op.go | il y a 9 ans | |
| sort.go | il y a 10 ans | |
| txn.go | il y a 9 ans | |
| txn_test.go | il y a 10 ans | |
| watch.go | il y a 9 ans | |
etcd/clientv3 is the official Go etcd client for v3.
go get github.com/coreos/etcd/clientv3
Create client using clientv3.New:
cli, err := clientv3.New(clientv3.Config{
Endpoints: []string{"localhost:12378", "localhost:22378", "localhost:32378"},
DialTimeout: 5 * time.Second,
})
if err != nil {
// handle error!
}
defer cli.Close()
etcd v3 uses gRPC for remote procedure calls. And clientv3 uses
grpc-go to connect to etcd. Make sure to close the client after using it.
If the client is not closed, the connection will have leaky goroutines. To specify client request timeout,
pass context.WithTimeout to APIs:
ctx, cancel := context.WithTimeout(context.Background(), timeout)
resp, err := kvc.Put(ctx, "sample_key", "sample_value")
cancel()
if err != nil {
// handle error!
}
// use the response
TODO
More code examples can be found at GoDoc.