etcdv3

package
v2.0.0-beta+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ROLE_LEADER   = "leader"
	ROLE_FOLLOWER = "follower"

	STATUS_HEALTHY   = "healthy"
	STATUS_UNHEALTHY = "unhealthy"
)
View Source
const (
	DEFAULT_DIR_VALUE = "etcdv3_dir_$2H#%gRe3*t"
)

Variables

View Source
var (
	ErrorPutKey      = errors.New("key is not under a directory or key is a directory or key is not empty")
	ErrorKeyNotFound = errors.New("key has not been set")
	ErrorListKey     = errors.New("can only list a directory")
)

错误类型

Functions

func NodeJsonFormat

func NodeJsonFormat(prefix string, list []*Node) (interface{}, error)

node 列表格式化成json

Types

type Etcd3Client

type Etcd3Client struct {
	*clientv3.Client
}

Etcd3Client etcd v3客户端

func GetEtcdCli

func GetEtcdCli(etcdCfg *config.EtcdServer) (*Etcd3Client, error)

GetEtcdCli 获取一个etcd cli对象

func NewEtcdCli

func NewEtcdCli(etcdCfg *config.EtcdServer) (*Etcd3Client, error)

NewEtcdCli 创建一个etcd客户端

func (*Etcd3Client) Delete

func (c *Etcd3Client) Delete(key string) error

Delete 删除key

func (*Etcd3Client) GetRecursiveValue

func (c *Etcd3Client) GetRecursiveValue(key string) (list []*Node, err error)

GetRecursiveValue 获取前缀下的所有key

func (*Etcd3Client) List

func (c *Etcd3Client) List(key string) (nodes []*Node, err error)

List 获取目录下列表

func (*Etcd3Client) Members

func (c *Etcd3Client) Members() ([]*Member, error)

Members 获取节点列表

func (*Etcd3Client) Put

func (c *Etcd3Client) Put(key string, value string, mustEmpty bool) error

Put 添加一个key

func (*Etcd3Client) Value

func (c *Etcd3Client) Value(key string) (val *Node, err error)

Value 获取一个key的值

type Member

type Member struct {
	*etcdserverpb.Member
	Role   string `json:"role"`
	Status string `json:"status"`
	DbSize int64  `json:"db_size"`
}

Member 节点信息

type Node

type Node struct {
	IsDir   bool   `json:"is_dir"`
	Version int64  `json:"version,string"`
	Value   string `json:"value"`
	FullDir string `json:"full_dir"`
}

Node 需要使用到的模型

func NewNode

func NewNode(dir string, kv *mvccpb.KeyValue) *Node

NewNode 创建节点

Jump to

Keyboard shortcuts

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