etcd

package
v2.6.1+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultRootPath is the root path of the keys stored in etcd.
	DefaultRootPath = "mysql/mysql-servers"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a wrapper of etcd client that support some simple method.

func NewClient

func NewClient(cli *clientv3.Client, root string) *Client

NewClient returns a wrapped etcd client.

func NewClientFromCfg

func NewClientFromCfg(endpoints []string,
	dialTimeout time.Duration,
	root string, clusterName, username, password string) (*Client, error)

NewClientFromCfg returns a customized wrapped etcd client.

func (*Client) Close

func (e *Client) Close() error

Close shutdown the connection to etcd.

func (*Client) Delete

func (e *Client) Delete(ctx context.Context, key string, withPrefixMatch bool) error

Delete deletes the `key/values` with matching prefix or key.

func (*Client) Get

func (e *Client) Get(ctx context.Context, key string) ([]byte, *mvccpb.KeyValue, error)

Get returns a key/value matches the given key. returns the value, leaderID and error respectively

func (*Client) KeyWithRootPath

func (e *Client) KeyWithRootPath(key string) string

KeyWithRootPath returns the full path of the key on etcd. when clientv3 api is used, all keys must be wrapped with this method for example, clientv3.Watch(ctx, client.KeyWithFullPath(key))

func (*Client) List

func (e *Client) List(ctx context.Context, key string) (*Node, error)

List returns the trie struct that contains key/value with same prefix.

func (*Client) MultiGet

func (e *Client) MultiGet(ctx context.Context, keys ...string) (map[string][]byte, error)

MultiGet returns the map struct that contains key/value within the given keys.

func (*Client) NewLease

func (e *Client) NewLease() clientv3.Lease

NewLease creates a new lessor

func (*Client) NewWatcher

func (e *Client) NewWatcher() clientv3.Watcher

NewWatcher creates a new watcher

func (*Client) PrefixGet

func (e *Client) PrefixGet(ctx context.Context, prefix string) (map[string][]byte, error)

PrefixGet returns the map struct that contains key/value with same prefix.

func (*Client) Put

func (e *Client) Put(ctx context.Context, k string, val string, opts ...clientv3.OpOption) error

Put guarantees to set a `key = value` with options.

func (*Client) Txn

func (e *Client) Txn(ctx context.Context) clientv3.Txn

Txn returns an etcd transaction

type Node

type Node struct {
	Value    []byte
	Children map[string]*Node
}

Node contains etcd query result as a Trie tree.

type URLsValue

type URLsValue types.URLs

URLsValue is an alias of URLs.

func NewURLsValue

func NewURLsValue(s string) (*URLsValue, error)

NewURLsValue returns a URLsValue from a string of URL list(separated by comma). e.g. http://192.168.0.2:2380, http://192.168.0.3:2380

func (*URLsValue) HostString

func (uv *URLsValue) HostString() string

HostString returns a string of 'host:port' list separated by comma.

func (*URLsValue) Set

func (uv *URLsValue) Set(s string) error

Set parses a string line of URL

func (*URLsValue) String

func (uv *URLsValue) String() string

String returns a string of etcd URLs separated by comma.

func (*URLsValue) StringSlice

func (uv *URLsValue) StringSlice() []string

StringSlice returns a slice of string with formatted URL.

func (*URLsValue) URLSlice

func (uv *URLsValue) URLSlice() []url.URL

URLSlice returns a slice of URLs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL