package
3.1.3+incompatible
Repository: https://github.com/jsok/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 := kvc.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 := kvc.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.

Examples

More code examples can be found at GoDoc.

# Packages

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 mirror implements etcd mirroring operations.
No description provided by the author

# 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.
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
NewFromConfigFile creates a new etcdv3 client from a configuration file.
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
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
RetryAuthClient implements a AuthClient that uses the client's FailFast retry policy.
RetryClusterClient implements a ClusterClient that uses the client's FailFast retry policy.
RetryKVClient implements a KVClient that uses the client's FailFast retry policy.
RetryLeaseClient implements a LeaseClient that uses the client's FailFast retry policy.
SetLogger sets client-side Logger.
No description provided by the author
No description provided by the author
No description provided by the author
WithAttachedKeys requests lease timetolive API to return attached keys of given lease ID.
WithCompactPhysical makes compact RPC call wait until the compaction is physically applied to the local database such that compacted entries are totally removed from the backend database.
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.
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
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

# 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 is used to convert the protobuf grant response.
LeaseKeepAliveResponse is used to convert the protobuf keepalive response.
LeaseOp represents an Operation that lease can execute.
LeaseTimeToLiveResponse is used to convert the protobuf lease timetolive response.
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
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
LeaseOption configures lease operations.
No description provided by the author
Logger is the logger used by client library.
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