etcd

package
v1.2.6 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//DefaultDialTimeout default dial timeout
	DefaultDialTimeout = 3 * time.Second

	//IgnoreRevision use -1 as ignore revision check
	IgnoreRevision = -1
)
View Source
const (
	//ChanBufferSize chan buffer size
	ChanBufferSize = 10
)

Variables

View Source
var (
	//ErrEmptyRoot root path empty is dangerous
	ErrEmptyRoot = errors.New("etcd.root.path.empty")
	//ErrInvalidPath invalid path
	ErrInvalidPath = errors.New("invalid.etcd.path")
)

Functions

func IsNotFoundErr

func IsNotFoundErr(err error) bool

IsNotFoundErr is not found

Types

type Client

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

Client etcd client

func NewClient

func NewClient(url string, root string, ops ...Option) (*Client, error)

NewClient new etcd client

func (*Client) Close

func (c *Client) Close() error

Close close

func (*Client) Create

func (c *Client) Create(ctx context.Context, nodePath string, content []byte) WRet

Create create node with value, if node exist fail

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, nodePath string, revision int64) WRet

Delete delete node

func (*Client) DeleteDir

func (c *Client) DeleteDir(ctx context.Context, nodePath string, revision int64) WRet

DeleteDir delete dir

func (*Client) Get

func (c *Client) Get(ctx context.Context, nodePath string, opts ...clientv3.OpOption) NodeRet

Get get node data

func (*Client) GetDir

func (c *Client) GetDir(ctx context.Context, nodePath string, keyOnly bool) DirRet

GetDir common get dir get dir - if keyOnly is false, get all dir children data.

func (*Client) Put

func (c *Client) Put(ctx context.Context, nodePath string, content []byte, revision int64) WRet

Put put node data

func (*Client) WatchDir

func (c *Client) WatchDir(ctx context.Context,
	nodePath string, timeout time.Duration, ignoreEmpty bool) (DirRet, <-chan DirEvent, context.CancelFunc)

WatchDir watch dir ctx -- cancel controller, it's a parent context for watch nodePath -- path timeout -- get dir timeout ignoreEmpty -- if ignore, even get nothing from dir, watch still continue to work return first get dir content/dir watch event/current watch session cancel

type Code

type Code int

Code error code

const (
	OK Code = iota
	//Unavailable server unavailable
	Unavailable
	//Timeout rpc timeout
	Timeout
	//Cancelled rpc cancelled
	Cancelled
	//NodeExist node not exist
	NodeExist
	//NodeNotFound node not found
	NodeNotFound
	//BadVersion bad version check
	BadVersion
	//BadRsp bad response
	BadRsp
	//WatchFail watch fail
	WatchFail
	//WatchUnexpected watch unexpected event
	WatchUnexpected
	//WatchClosed watch closed
	WatchClosed
	//Unknown unknown error
	Unknown
)

func ErrCode

func ErrCode(err error) Code

ErrCode get error code of etcd

type DirEvent

type DirEvent struct {
	Events   []*clientv3.Event
	Err      error
	Revision int64
}

DirEvent dir event

func (*DirEvent) AddEvent

func (w *DirEvent) AddEvent(e *clientv3.Event)

AddEvent add event

func (*DirEvent) DebugInfo

func (w *DirEvent) DebugInfo() string

DebugInfo debug info

type DirRet

type DirRet struct {
	KVS      []*mvccpb.KeyValue
	Err      error
	Revision int64
}

DirRet Read Dir Ret

func (*DirRet) DebugInfo

func (d *DirRet) DebugInfo() string

DebugInfo debug info

func (*DirRet) ExceptNotFoundErr

func (d *DirRet) ExceptNotFoundErr() bool

ExceptNotFoundErr dir ret is error except "not found"

type Error

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

Error error define

func (*Error) Code

func (e *Error) Code() Code

func (*Error) Error

func (e *Error) Error() string

type NodeRet

type NodeRet struct {
	Data     []byte
	Err      error
	Revision int64
}

NodeRet Read Node Ret

type Option

type Option func(*_Option)

Option setup option

func WithDialTimeout

func WithDialTimeout(timeout time.Duration) Option

WithDialTimeout set dial timeout

func WithTLS

func WithTLS(certPath, keyPath, caPath string) Option

WithTLS set tls

type WRet

type WRet struct {
	Revision int64
	Err      error
}

WRet Write Ret

type Watcher

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

func NewWatcher

func NewWatcher(cli *Client, path string, timeout, backoff time.Duration) *Watcher

NewWatcher new watcher

func (*Watcher) DirChan

func (w *Watcher) DirChan() <-chan DirEvent

DirChan dir chan

func (*Watcher) StartWatchDir

func (w *Watcher) StartWatchDir()

StartWatchDir loop watch dir -- if chan closed, which means go routine out

func (*Watcher) StartWatchDirWhenExist

func (w *Watcher) StartWatchDirWhenExist()

StartWatchDirWhenExist loop watch dir -- if chan closed, which means go routine out only in case there is any key under the watch path

func (*Watcher) Stop

func (w *Watcher) Stop()

Stop stop loop watch

Directories

Path Synopsis
test

Jump to

Keyboard shortcuts

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