package
3.3.8+incompatible
Repository: https://github.com/jiajunhuang/etcd.git
Documentation: pkg.go.dev

# README

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

etcd uses cmd/vendor directory to store external dependencies, which are to be compiled into etcd release binaries. client can be imported without vendoring. For full compatibility, it is recommended to vendor builds using etcd's vendored packages, using tools like godep, as in vendor directories. For more detail, please read Go vendor design.

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.

Examples

More code examples can be found at GoDoc.

# Packages

Package clientv3util contains utility functions derived from clientv3.
Package concurrency implements concurrency operations on top of etcd such as distributed locks, barriers, and elections.
Package integration implements tests built upon embedded etcd, and focuses on correctness of etcd client.
Package leasing serves linearizable reads from a local cache by acquiring exclusive write access to keys through a client-side leasing protocol.
Package mirror implements etcd mirroring operations.
Package namespace is a clientv3 wrapper that translates all keys to begin with a given prefix.
Package naming provides an etcd-backed gRPC resolver for discovering gRPC services.
Package ordering is a clientv3 wrapper that caches response header revisions to detect ordering violations from stale responses.
Package yaml handles yaml-formatted clientv3 configuration data.

# Functions

No description provided by the author
No description provided by the author
GetLogger returns the current logger.
GetPrefixRangeEnd gets the range end of the prefix.
LeaseValue compares a key's LeaseID to a value of your choosing.
No description provided by the author
New creates a new etcdv3 client from a given configuration.
No description provided by the author
No description provided by the author
No description provided by the author
NewCtxClient creates a client with a context but no underlying grpc connection.
NewFromURL creates a new etcdv3 client from a URL.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NewLogger returns a new Logger with grpclog.LoggerV2.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
OpCompact wraps slice CompactOption to create a CompactOp.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
RetryAuthClient implements a AuthClient.
RetryClusterClient implements a ClusterClient.
RetryKVClient implements a KVClient.
RetryLeaseClient implements a LeaseClient.
RetryMaintenanceClient implements a Maintenance.
SetLogger sets client-side Logger.
No description provided by the author
No description provided by the author
No description provided by the author
WithAttachedKeys makes TimeToLive list the keys attached to the given lease ID.
WithCompactPhysical makes Compact wait until all compacted entries are removed from the etcd server's storage.
WithCountOnly makes the 'Get' request return only the count of keys.
WithCreatedNotify makes watch server sends the created event.
WithFilterDelete discards DELETE events from the watcher.
WithFilterPut discards PUT events from the watcher.
WithFirstCreate gets the key with the oldest creation revision in the request range.
WithFirstKey gets the lexically first key in the request range.
WithFirstRev gets the key with the oldest modification revision in the request range.
WithFromKey specifies the range of 'Get', 'Delete', 'Watch' requests to be equal or greater than the key in the argument.
WithIgnoreLease updates the key using its current lease.
WithIgnoreValue updates the key using its current value.
WithKeysOnly makes the 'Get' request return only the keys and the corresponding values will be omitted.
WithLastCreate gets the key with the latest creation revision in the request range.
WithLastKey gets the lexically last key in the request range.
WithLastRev gets the key with the latest modification revision in the request range.
WithLease attaches a lease ID to a key in 'Put' request.
WithLimit limits the number of results to return from 'Get' request.
WithMaxCreateRev filters out keys for Get with creation revisions greater than the given revision.
WithMaxModRev filters out keys for Get with modification revisions greater than the given revision.
WithMinCreateRev filters out keys for Get with creation revisions less than the given revision.
WithMinModRev filters out keys for Get with modification revisions less than the given revision.
WithPrefix enables 'Get', 'Delete', or 'Watch' requests to operate on the keys with matching prefix.
WithPrevKV gets the previous key-value pair before the event happens.
WithProgressNotify makes watch server send periodic progress updates every 10 minutes when there is no incoming events.
WithRange specifies the range of 'Get', 'Delete', 'Watch' requests.
WithRequireLeader requires client requests to only succeed when the cluster has a leader.
WithRev specifies the store revision for 'Get' request.
WithSerializable makes 'Get' request serializable.
WithSort specifies the ordering in 'Get' request.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
MaxLeaseTTL is the maximum lease TTL value.
NoLease is a lease ID for the absence of a lease.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

ErrNoAddrAvilable is returned by Get() when the balancer does not have any active connection to endpoints at the time.
No description provided by the author
No description provided by the author

# Structs

Client provides and manages an etcd v3 client session.
CompactOp represents a compact operation.
No description provided by the author
ErrKeepAliveHalted is returned if client keep alive loop halts with an unexpected error.
LeaseGrantResponse wraps the protobuf message LeaseGrantResponse.
LeaseKeepAliveResponse wraps the protobuf message LeaseKeepAliveResponse.
LeaseLeasesResponse wraps the protobuf message LeaseLeasesResponse.
LeaseOp represents an Operation that lease can execute.
LeaseStatus represents a lease status.
LeaseTimeToLiveResponse wraps the protobuf message LeaseTimeToLiveResponse.
Op represents an Operation that kv can execute.
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Logger is the logger used by client library.
No description provided by the author
Txn is the interface that wraps mini-transactions.
No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
CompactOption configures compact operation.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
LeaseOption configures lease operations.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
OpOption configures Operations like Get, Put, Delete.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author