Documentation ¶
Index ¶
- Variables
- func DeleteResult(resp *clientv3.DeleteResponse, err error) (int64, error)
- func GetResult(resp *clientv3.GetResponse, err error) (map[string]string, error)
- func GetResultCount(resp *clientv3.GetResponse, err error) (int64, error)
- func GetResultInt(resp *clientv3.GetResponse, err error) (int, error)
- func GetResultInts(resp *clientv3.GetResponse, err error) ([]int, error)
- func GetResultString(resp *clientv3.GetResponse, err error) (string, error)
- func GetResultStrings(resp *clientv3.GetResponse, err error) ([]string, error)
- func IsErrLockNotAcquired(err error) bool
- func LeaseGrantResult(resp *clientv3.LeaseGrantResponse, err error) (clientv3.LeaseID, error)
- func LeaseRevokeResult(_ *clientv3.LeaseRevokeResponse, err error) error
- func LeaseTimeToLiveResult(resp *clientv3.LeaseTimeToLiveResponse, err error) (int64, error)
- func PutResult(_ *clientv3.PutResponse, err error) error
- func TxnResult(_ *clientv3.TxnResponse, err error) error
- type ClientOption
- func WithCACertPath(caCertPath string) ClientOption
- func WithPassword(password string) ClientOption
- func WithTLSCertPath(tlsCertPath string) ClientOption
- func WithTLSKeyPath(tlsKeyPath string) ClientOption
- func WithTarget(target string) ClientOption
- func WithTimeout(timeout int) ClientOption
- func WithUsername(username string) ClientOption
- type ClientProxy
- type LeaseProxy
- type LockerProxy
Constants ¶
This section is empty.
Variables ¶
var ( // ErrLockNotAcquired lock not acquired ErrLockNotAcquired = errors.New("lock not acquired") )
var ( // ErrNil result nil error ErrNil = errors.New("result nil") )
Functions ¶
func DeleteResult ¶
func DeleteResult(resp *clientv3.DeleteResponse, err error) (int64, error)
DeleteResult is a helper that return the deleted raw number of etcd delete operation
func GetResult ¶
GetResult is a helper that converts the response of an etcd get operation to a mapa[string]string
func GetResultCount ¶
func GetResultCount(resp *clientv3.GetResponse, err error) (int64, error)
GetResultCount is a helper that return the count in the response of an etcd get operation
func GetResultInt ¶
func GetResultInt(resp *clientv3.GetResponse, err error) (int, error)
GetResultInt is a helper that converts the first value in the response of an etcd get operation to a int
Return ErrNil when response count euqal 0.
func GetResultInts ¶
func GetResultInts(resp *clientv3.GetResponse, err error) ([]int, error)
GetResultInts is a helper that converts the first value in the response of an etcd get operation to a []int
Return ErrNil when response count euqal 0.
func GetResultString ¶
func GetResultString(resp *clientv3.GetResponse, err error) (string, error)
GetResultString is a helper that converts the first value in the response of an etcd get operation to a string
Return ErrNil when response count euqal 0.
func GetResultStrings ¶
func GetResultStrings(resp *clientv3.GetResponse, err error) ([]string, error)
GetResultStrings is a helper that converts the first value in the response of an etcd get operation to a []string
Return ErrNil when response count euqal 0.
func IsErrLockNotAcquired ¶ added in v1.1.0
IsErrLockNotAcquired is lock not acquired error
func LeaseGrantResult ¶
LeaseGrantResult is a helper that return lease id in the response of an etcd lease grant operation
func LeaseRevokeResult ¶
func LeaseRevokeResult(_ *clientv3.LeaseRevokeResponse, err error) error
LeaseRevokeResult is a helper that converts etcd lease revoke operation response to an error
func LeaseTimeToLiveResult ¶
func LeaseTimeToLiveResult(resp *clientv3.LeaseTimeToLiveResponse, err error) (int64, error)
LeaseTimeToLiveResult is a helper that return lease ttl in the response of an etcd lease grant operation
Types ¶
type ClientOption ¶
type ClientOption func(*clientConfig)
ClientOption etcd client proxy option
func WithCACertPath ¶
func WithCACertPath(caCertPath string) ClientOption
WithCACertPath set ca cert file path
func WithPassword ¶
func WithPassword(password string) ClientOption
WithPassword set password for authentication
func WithTLSCertPath ¶
func WithTLSCertPath(tlsCertPath string) ClientOption
WithTLSKeyPath set tls cert file path
func WithTLSKeyPath ¶
func WithTLSKeyPath(tlsKeyPath string) ClientOption
WithTLSKeyPath set tls key file path
func WithTarget ¶
func WithTarget(target string) ClientOption
WithTarget set target
Target is a list of URLs, multiple URL split by ','
func WithTimeout ¶
func WithTimeout(timeout int) ClientOption
WithTimeout set timeout
Unit millisecond, default 3000
func WithUsername ¶
func WithUsername(username string) ClientOption
WithUsername set user name for authentication
type ClientProxy ¶
type ClientProxy interface { // Put puts a key-value pair into etcd. // Note that key,value can be plain bytes array and string is // an immutable representation of that bytes array. // To get a string of bytes, do string([]byte{0x10, 0x20}). Put(ctx context.Context, key, val string, opts ...clientv3.OpOption) (*clientv3.PutResponse, error) // Get retrieves keys. // By default, Get will return the value for "key", if any. // When passed WithRange(end), Get will return the keys in the range [key, end). // When passed WithFromKey(), Get returns keys greater than or equal to key. // When passed WithRev(rev) with rev > 0, Get retrieves keys at the given revision; // if the required revision is compacted, the request will fail with ErrCompacted . // When passed WithLimit(limit), the number of returned keys is bounded by limit. // When passed WithSort(), the keys will be sorted. Get(ctx context.Context, key string, opts ...clientv3.OpOption) (*clientv3.GetResponse, error) // Delete deletes a key, or optionally using WithRange(end), [key, end). Delete(ctx context.Context, key string, opts ...clientv3.OpOption) (*clientv3.DeleteResponse, error) // Watch watches on a key or prefix. The watched events will be returned // through the returned channel. If revisions waiting to be sent over the // watch are compacted, then the watch will be canceled by the server, the // client will post a compacted error watch response, and the channel will close. // If the requested revision is 0 or unspecified, the returned channel will // return watch events that happen after the server receives the watch request. // If the context "ctx" is canceled or timed out, returned "WatchChan" is closed, // and "WatchResponse" from this closed channel has zero events and nil "Err()". // The context "ctx" MUST be canceled, as soon as watcher is no longer being used, // to release the associated resources. // // If the context is "context.Background/TODO", returned "WatchChan" will // not be closed and block until event is triggered, except when server // returns a non-recoverable error (e.g. ErrCompacted). // For example, when context passed with "WithRequireLeader" and the // connected server has no leader (e.g. due to network partition), // error "etcdserver: no leader" (ErrNoLeader) will be returned, // and then "WatchChan" is closed with non-nil "Err()". // In order to prevent a watch stream being stuck in a partitioned node, // make sure to wrap context with "WithRequireLeader". // // Otherwise, as long as the context has not been canceled or timed out, // watch will retry on other recoverable errors forever until reconnected. Watch(ctx context.Context, key string, opts ...clientv3.OpOption) (clientv3.WatchChan, error) // Txn creates a transaction. // // Step 1: // If takes a list of comparison. If all comparisons passed in succeed, // the operations passed into Then() will be executed. Or the operations // passed into Else() will be executed. // // Step 2: // Then takes a list of operations. The Ops list will be executed, if the // comparisons passed in If() succeed. // // Else takes a list of operations. The Ops list will be executed, if the // comparisons passed in If() fail. // // Step 3: // Commit tries to commit the transaction. Txn(ctx context.Context, cmps []clientv3.Cmp, thenOps []clientv3.Op, elseOps []clientv3.Op) (*clientv3.TxnResponse, error) // Lease get etcd lease proxy Lease() LeaseProxy // Locker gets the lock operation proxy for the key prefix. // // It while create an leased session and keep the lease alive until client error // or invork close function. Locker(prefix string, ttl int) (LockerProxy, error) }
ClientProxy etcd client proxy
func NewClientProxy ¶
func NewClientProxy(name string, opts ...ClientOption) ClientProxy
NewClientProxy new etcd client proxy
type LeaseProxy ¶
type LeaseProxy interface { // Grant creates a new lease. Grant(ctx context.Context, ttl int64) (*clientv3.LeaseGrantResponse, error) // Revoke revokes the given lease. Revoke(ctx context.Context, id clientv3.LeaseID) (*clientv3.LeaseRevokeResponse, error) // TimeToLive retrieves the lease information of the given lease ID. TimeToLive(ctx context.Context, id clientv3.LeaseID, opts ...clientv3.LeaseOption) (*clientv3.LeaseTimeToLiveResponse, error) // Leases retrieves all leases. Leases(ctx context.Context) (*clientv3.LeaseLeasesResponse, error) // KeepAlive attempts to keep the given lease alive forever. If the keepalive responses posted // to the channel are not consumed promptly the channel may become full. When full, the lease // client will continue sending keep alive requests to the etcd server, but will drop responses // until there is capacity on the channel to send more responses. // // If client keep alive loop halts with an unexpected error (e.g. "etcdserver: no leader") or // canceled by the caller (e.g. context.Canceled), KeepAlive returns a ErrKeepAliveHalted error // containing the error reason. // // The returned "LeaseKeepAliveResponse" channel closes if underlying keep // alive stream is interrupted in some way the client cannot handle itself; // given context "ctx" is canceled or timed out. KeepAlive(ctx context.Context, id clientv3.LeaseID) (<-chan *clientv3.LeaseKeepAliveResponse, error) }
LeaseProxy etcd lease proxy
type LockerProxy ¶ added in v1.1.0
type LockerProxy interface { // Lock locks the mutex with a cancelable context. If the context is canceled // while trying to acquire the lock, the mutex tries to clean its stale lock entry. Lock(ctx context.Context) error // TryLock locks the mutex if not already locked by another session. // If lock is held by another session, return immediately after attempting necessary cleanup // The ctx argument is used for the sending/receiving Txn RPC. // Return 'ErrLockNotAcquired' when lock not acquired. TryLock(ctx context.Context) error // Unlock // Return error if the lock key delete fail. Unlock(ctx context.Context) error // Close orphans the session and revokes the session lease. Close() error }
LockerProxy etcd locker proxy