etcd/clientv3
Gyu-Ho Lee 53f94c22b3 Merge pull request #4600 from gyuho/opoption_doc
clientv3: add GoDoc to OpOption
2016-02-23 15:36:38 -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-23 15:07:10 -08:00
2016-02-23 15:18:33 -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.