• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..25-Jul-2019-

balancer/H25-Jul-2019-1,5741,038

concurrency/H25-Jul-2019-987676

README.mdH A D25-Jul-20192.9 KiB8863

auth.goH A D25-Jul-20199.3 KiB233160

client.goH A D25-Jul-201918.8 KiB669512

cluster.goH A D25-Jul-20193.3 KiB11575

compact_op.goH A D25-Jul-20191.5 KiB5225

compare.goH A D25-Jul-20193.6 KiB14195

config.goH A D25-Jul-20193.1 KiB8525

doc.goH A D25-Jul-20193.6 KiB1071

kv.goH A D25-Jul-20195.6 KiB178121

lease.goH A D25-Jul-201915.4 KiB597432

logger.goH A D25-Jul-20193.3 KiB10269

maintenance.goH A D25-Jul-20196.7 KiB231171

op.goH A D25-Jul-201917.5 KiB561350

options.goH A D25-Jul-20192.7 KiB6617

ready_wait.goH A D25-Jul-2019955 3112

retry.goH A D25-Jul-201912.1 KiB299196

retry_interceptor.goH A D25-Jul-201912.6 KiB396308

sort.goH A D25-Jul-2019888 3819

txn.goH A D25-Jul-20193 KiB15285

utils.goH A D25-Jul-20191.5 KiB5025

watch.goH A D25-Jul-201925.2 KiB987701

README.md

1# etcd/clientv3
2
3[![Docs](https://readthedocs.org/projects/etcd/badge/?version=latest&style=flat-square)](https://etcd.readthedocs.io/en/latest/?badge=latest)
4[![Godoc](https://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](https://godoc.org/go.etcd.io/etcd/clientv3)
5
6`etcd/clientv3` is the official Go etcd client for v3.
7
8See https://etcd.readthedocs.io/en/latest for latest client architecture.
9
10## Install
11
12```bash
13go get go.etcd.io/etcd/clientv3
14```
15
16## Get started
17
18Create client using `clientv3.New`:
19
20```go
21cli, err := clientv3.New(clientv3.Config{
22	Endpoints:   []string{"localhost:2379", "localhost:22379", "localhost:32379"},
23	DialTimeout: 5 * time.Second,
24})
25if err != nil {
26	// handle error!
27}
28defer cli.Close()
29```
30
31etcd v3 uses [`gRPC`](https://www.grpc.io) for remote procedure calls. And `clientv3` uses
32[`grpc-go`](https://github.com/grpc/grpc-go) to connect to etcd. Make sure to close the client after using it.
33If the client is not closed, the connection will have leaky goroutines. To specify client request timeout,
34pass `context.WithTimeout` to APIs:
35
36```go
37ctx, cancel := context.WithTimeout(context.Background(), timeout)
38resp, err := cli.Put(ctx, "sample_key", "sample_value")
39cancel()
40if err != nil {
41    // handle error!
42}
43// use the response
44```
45
46For full compatibility, it is recommended to vendor builds using etcd's vendored packages, using tools like `golang/dep`, as in [vendor directories](https://golang.org/cmd/go/#hdr-Vendor_Directories).
47
48## Error Handling
49
50etcd client returns 2 types of errors:
51
521. context error: canceled or deadline exceeded.
532. gRPC error: see [api/v3rpc/rpctypes](https://godoc.org/go.etcd.io/etcd/etcdserver/api/v3rpc/rpctypes).
54
55Here is the example code to handle client errors:
56
57```go
58resp, err := cli.Put(ctx, "", "")
59if err != nil {
60	switch err {
61	case context.Canceled:
62		log.Fatalf("ctx is canceled by another routine: %v", err)
63	case context.DeadlineExceeded:
64		log.Fatalf("ctx is attached with a deadline is exceeded: %v", err)
65	case rpctypes.ErrEmptyKey:
66		log.Fatalf("client-side error: %v", err)
67	default:
68		log.Fatalf("bad cluster endpoints, which are not etcd servers: %v", err)
69	}
70}
71```
72
73## Metrics
74
75The etcd client optionally exposes RPC metrics through [go-grpc-prometheus](https://github.com/grpc-ecosystem/go-grpc-prometheus). See the [examples](https://github.com/etcd-io/etcd/blob/master/clientv3/example_metrics_test.go).
76
77## Namespacing
78
79The [namespace](https://godoc.org/go.etcd.io/etcd/clientv3/namespace) package provides `clientv3` interface wrappers to transparently isolate client requests to a user-defined prefix.
80
81## Request size limit
82
83Client request size limit is configurable via `clientv3.Config.MaxCallSendMsgSize` and `MaxCallRecvMsgSize` in bytes. If none given, client request send limit defaults to 2 MiB including gRPC overhead bytes. And receive limit defaults to `math.MaxInt32`.
84
85## Examples
86
87More code examples can be found at [GoDoc](https://godoc.org/go.etcd.io/etcd/clientv3).
88