etcd/clientv3
Ajit Yagaty 606889a002 clientv3: Fix inconsistent naming convention in v3 client.
In order to have a consistent naming for variable/function names
pertaining to ModifiedRevision, all occurrences have been renamed
to ModRevision.
2016-03-22 14:58:11 -07:00
..
concurrency clientv3: Fix inconsistent naming convention in v3 client. 2016-03-22 14:58:11 -07:00
integration clientv3: Fix inconsistent naming convention in v3 client. 2016-03-22 14:58:11 -07:00
mirror *: godoc clean up 2016-03-19 14:19:23 -07:00
README.md *: gRPC + HTTP on the same port 2016-03-21 14:29:25 -07:00
auth.go clientv3: a new interface Auth for auth related RPCs 2016-03-02 15:17:59 +09:00
client.go *: add client.defrag and defrag cmd for etcdctl 2016-03-10 09:30:41 -08:00
client_test.go clientv3: do not reconnect on request context cancellation 2016-03-03 13:43:16 -08:00
cluster.go clientv3: do not reconnect on request context cancellation 2016-03-03 13:43:16 -08:00
compare.go clientv3: Fix inconsistent naming convention in v3 client. 2016-03-22 14:58:11 -07:00
doc.go *: gRPC + HTTP on the same port 2016-03-21 14:29:25 -07:00
example_cluster_test.go *: gRPC + HTTP on the same port 2016-03-21 14:29:25 -07:00
example_kv_test.go clientv3: use default client kv 2016-02-25 18:13:26 -08:00
example_lease_test.go clientv3: remove dependency on lease package 2016-03-17 11:52:34 -07:00
example_test.go *: gRPC + HTTP on the same port 2016-03-21 14:29:25 -07:00
example_watch_test.go clientv3: add IsProgressNotify with example 2016-03-04 12:16:43 -08:00
kv.go clientv3: set Serializable from Op 2016-03-18 15:56:48 -07:00
lease.go clientv3: remove dependency on lease package 2016-03-17 11:52:34 -07:00
maintenance.go *: add client.defrag and defrag cmd for etcdctl 2016-03-10 09:30:41 -08:00
op.go clientv3: Fix inconsistent naming convention in v3 client. 2016-03-22 14:58:11 -07:00
sort.go clientv3: Fix inconsistent naming convention in v3 client. 2016-03-22 14:58:11 -07:00
txn.go clientv3: do not reconnect on request context cancellation 2016-03-03 13:43:16 -08:00
txn_test.go clientv3: optionize put and delete 2016-02-10 15:03:11 -08:00
watch.go v3rpc: move errors to v3rpc/rpctypes 2016-03-17 11:52:34 -07:00

README.md

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:2379", "localhost:22379", "localhost:32379"},
	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

etcd client returns 2 types of errors:

  1. context error: canceled or deadline exceeded.
  2. gRPC error: see v3rpc/error.

Here is the example code to handle client errors:

resp, err := kvc.Put(ctx, "", "")
if err != nil {
	if err == context.Canceled {
		// ctx is canceled by another routine
	} else if err == context.DeadlineExceeded {
		// ctx is attached with a deadline and it exceeded
	} else if verr, ok := err.(*v3rpc.ErrEmptyKey); ok {
		// process (verr.Errors)
	} else {
		// bad cluster endpoints, which are not etcd servers
	}
}

Examples

More code examples can be found at GoDoc.