etcd/client/v3
Chao Chen b2c39fc8e6 2023-06-06: bump up dependencies update identified by dependabot
Signed-off-by: Chao Chen <chaochn@amazon.com>
2023-06-06 20:18:44 -07:00
..
clientv3util all: goimports -w . 2022-11-17 19:07:04 +03:00
concurrency Fix goimports in all existing files. Execution of ./scripts/fix.sh 2022-12-29 09:41:31 +01:00
credentials Goimports: Apply automated fixing to test files as well. 2022-12-29 13:04:45 +01:00
experimental/recipes fix some comments 2023-04-20 14:26:17 +08:00
internal Fix goimports in all existing files. Execution of ./scripts/fix.sh 2022-12-29 09:41:31 +01:00
leasing Bump go 1.19: update all the dependencies and go.sum files 2022-09-22 08:47:46 +08:00
mirror cv3/mirror: Fetch the most recent prefix revision 2022-04-11 13:42:03 +00:00
mock/mockserver Mockserver can handle requests to the leases API 2022-09-06 18:48:51 +03:00
namespace all: goimports -w . 2022-11-17 19:07:04 +03:00
naming clientv3/naming/endpoints: fix endpoints prefix bug 2022-12-22 13:36:16 +03:00
ordering all: goimports -w . 2022-11-17 19:07:04 +03:00
snapshot clientv3: refactor snapshot SaveWithVersion 2023-05-22 09:09:02 +08:00
yaml all: goimports -w . 2022-11-17 19:07:04 +03:00
LICENSE client/v3: Create and update go.mod 2020-10-20 10:09:12 +02:00
README.md client: README: update to new go.mod paths 2021-06-15 19:47:22 -07:00
auth.go Fix goimports in all existing files. Execution of ./scripts/fix.sh 2022-12-29 09:41:31 +01:00
client.go Fix goimports in all existing files. Execution of ./scripts/fix.sh 2022-12-29 09:41:31 +01:00
client_test.go clientv3: support serializable MemberList operation 2023-02-25 07:23:39 +08:00
cluster.go clientv3: support serializable MemberList operation 2023-02-25 07:23:39 +08:00
compact_op.go clientv3: Move to client/v3 (just file move) 2020-10-20 10:08:35 +02:00
compact_op_test.go clientv3: Move to client/v3 (just file move) 2020-10-20 10:08:35 +02:00
compare.go clientv3: Move to client/v3 (just file move) 2020-10-20 10:08:35 +02:00
config.go docs: fix max recv msg size description 2022-11-17 10:37:55 +08:00
config_test.go clientv3: fix --insecure-skip-tls-verify not working when not specify --cert-path and --key-path 2022-08-08 16:24:12 +08:00
ctx.go Fix goimports in all existing files. Execution of ./scripts/fix.sh 2022-12-29 09:41:31 +01:00
ctx_test.go Goimports: Apply automated fixing to test files as well. 2022-12-29 13:04:45 +01:00
doc.go Bump go 1.19: update all the dependencies and go.sum files 2022-09-22 08:47:46 +08:00
example_auth_test.go clientv3: Move to client/v3 (just file move) 2020-10-20 10:08:35 +02:00
example_cluster_test.go clientv3: Move to client/v3 (just file move) 2020-10-20 10:08:35 +02:00
example_kv_test.go clientv3: Move to client/v3 (just file move) 2020-10-20 10:08:35 +02:00
example_lease_test.go clientv3: Move to client/v3 (just file move) 2020-10-20 10:08:35 +02:00
example_maintenance_test.go clientv3: Move to client/v3 (just file move) 2020-10-20 10:08:35 +02:00
example_metrics_test.go clientv3: Move to client/v3 (just file move) 2020-10-20 10:08:35 +02:00
example_test.go clientv3: Move to client/v3 (just file move) 2020-10-20 10:08:35 +02:00
example_watch_test.go clientv3: Move to client/v3 (just file move) 2020-10-20 10:08:35 +02:00
go.mod 2023-06-06: bump up dependencies update identified by dependabot 2023-06-06 20:18:44 -07:00
go.sum 2023-06-06: bump up dependencies update identified by dependabot 2023-06-06 20:18:44 -07:00
kv.go etcd: format import order 2022-09-20 18:41:39 +08:00
lease.go clientv3: close streams after use in lessor keepAliveOnce method 2022-08-17 18:02:13 -07:00
logger.go Fix goimports in all existing files. Execution of ./scripts/fix.sh 2022-12-29 09:41:31 +01:00
main_test.go Migrate dependencies pkg/foo -> client/pkg/foo 2021-04-07 00:38:47 +02:00
maintenance.go Fix goimports in all existing files. Execution of ./scripts/fix.sh 2022-12-29 09:41:31 +01:00
op.go clientv3: update etcdctl's readme and comment of clientv3.WithSerializable to clarify the use cases 2023-02-25 07:23:39 +08:00
op_test.go Client: fix check for WithPrefix op 2022-06-29 17:52:05 -04:00
options.go client/v3: fix comment typo 2023-01-07 14:40:12 +08:00
retry.go clientv3: Move to client/v3 (just file move) 2020-10-20 10:08:35 +02:00
retry_interceptor.go fix(client):getToken automatically when the token has expired 2023-01-30 15:19:53 +08:00
retry_interceptor_test.go add missing copyright headers 2022-11-23 19:13:43 +11:00
sort.go clientv3: Move to client/v3 (just file move) 2020-10-20 10:08:35 +02:00
txn.go Bump go 1.19: update all the dependencies and go.sum files 2022-09-22 08:47:46 +08:00
txn_test.go tests: use separate errc for each case in TestTxnPanics 2023-04-10 09:16:39 +08:00
utils.go fix IsOptsWithFromKey 2021-09-10 00:44:52 +08:00
watch.go clientv3: correct the nextRev on receving progress notification response 2023-02-10 09:09:19 +08:00
watch_test.go client: enhance the function shouldRetryWatch and added unit test 2022-12-13 06:05:02 +08:00

README.md

etcd/client/v3

Docs Godoc

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

Install

go get go.etcd.io/etcd/client/v3

Get started

Create client using clientv3.New:

import clientv3 "go.etcd.io/etcd/client/v3"

func main() {
	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 := cli.Put(ctx, "sample_key", "sample_value")
cancel()
if err != nil {
    // handle error!
}
// use the response

For full compatibility, it is recommended to install released versions of clients using go modules.

Error Handling

etcd client returns 2 types of errors:

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

Here is the example code to handle client errors:

resp, err := cli.Put(ctx, "", "")
if err != nil {
	switch err {
	case context.Canceled:
		log.Fatalf("ctx is canceled by another routine: %v", err)
	case context.DeadlineExceeded:
		log.Fatalf("ctx is attached with a deadline is exceeded: %v", err)
	case rpctypes.ErrEmptyKey:
		log.Fatalf("client-side error: %v", err)
	default:
		log.Fatalf("bad cluster endpoints, which are not etcd servers: %v", err)
	}
}

Metrics

The etcd client optionally exposes RPC metrics through go-grpc-prometheus. See the examples.

Namespacing

The namespace package provides clientv3 interface wrappers to transparently isolate client requests to a user-defined prefix.

Request size limit

Client 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.

Examples

More code examples can be found at GoDoc.