etcd/clientv3
Anthony Romano d02b1c982f clientv3: return closed channel on Watch() cancel
was returning nil; difficult to use correctly

Fixes #4626
2016-02-26 12:16:41 -08:00
..
2016-02-24 17:23:40 -08:00
2016-01-30 18:15:56 -08:00
2016-02-21 20:36:44 -08:00
2016-02-11 13:55:38 -08:00
2016-02-23 14:05:36 -08:00
2016-02-25 17:33:47 -08:00
2016-02-25 17:33:47 -08:00
2016-02-24 17:23:40 -08:00
2016-02-23 14:05:36 -08:00
2016-01-28 08:17:53 -08:00
2016-02-10 15:03:11 -08:00

etcd/clientv3

Godoc

etcd/clientv3 is the official Go etcd client for v3.

Install

go get github.com/coreos/etcd/clientv3

Get started

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

Error Handling

TODO

Examples

More code examples can be found at GoDoc.