Documentation
¶
Overview ¶
Copyright 2016 ~ 2018 AlexStocks(https://github.com/AlexStocks). All rights reserved. Use of this source code is governed by Apache License 2.0.
gxetcd encapsulate a etcd lease client
Copyright 2016 ~ 2018 AlexStocks(https://github.com/AlexStocks). All rights reserved. Use of this source code is governed by Apache License 2.0.
gxetcd encapsulate a etcd lease client
Index ¶
- type Client
- func (c *Client) Close() error
- func (c *Client) Done() <-chan struct{}
- func (c *Client) EtcdClient() *ecv3.Client
- func (c *Client) IsClosed() bool
- func (c *Client) KeepAlive() (<-chan *ecv3.LeaseKeepAliveResponse, error)
- func (c *Client) Lease() ecv3.LeaseID
- func (c *Client) Stop()
- func (c *Client) TTL() int64
- type ClientOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client represents a lease kept alive for the lifetime of a client. Fault-tolerant applications may use sessions to reason about liveness.
func NewClient ¶
func NewClient(client *ecv3.Client, options ...ClientOption) (*Client, error)
NewClient gets the leased session for a client.
func (*Client) Done ¶
func (c *Client) Done() <-chan struct{}
Done returns a channel that closes when the lease is orphaned, expires, or is otherwise no longer being refreshed.
func (*Client) EtcdClient ¶
Client is the etcd client that is attached to the session.
func (*Client) KeepAlive ¶
func (c *Client) KeepAlive() (<-chan *ecv3.LeaseKeepAliveResponse, error)
type ClientOption ¶
type ClientOption func(*clientOptions)
ClientOption configures Client.
func WithContext ¶
func WithContext(ctx context.Context) ClientOption
WithContext assigns a context to the session instead of defaulting to using the client context. This is useful for canceling NewClient and Close operations immediately without having to close the client. If the context is canceled before Close() completes, the session's lease will be abandoned and left to expire instead of being revoked.
func WithLease ¶
func WithLease(leaseID ecv3.LeaseID) ClientOption
WithLease specifies the existing leaseID to be used for the session. This is useful in process restart scenario, for example, to reclaim leadership from an election prior to restart.
func WithTTL ¶
func WithTTL(ttl time.Duration) ClientOption
WithTTL configures the session's TTL in seconds. If TTL is <= 0, the default 60 seconds TTL will be used.