etcd

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	Watch(key string, opts ...clientv3.OpOption)
	Put(key string, value string, timeout time.Duration, opts ...clientv3.OpOption) (resp *clientv3.PutResponse, err error)
	Get(key string) (value interface{}, exists bool)
	GetRemote(key string, timeout time.Duration) (kvs []*mvccpb.KeyValue, err error)
	Delete(key string, timeout time.Duration, opts ...clientv3.OpOption) (resp *clientv3.DeleteResponse, err error)
	Connection() (client *clientv3.Client)
	Close() (err error)
}

func NewClient

func NewClient(conf *clientv3.Config, prefixes []string, keyItems map[string]Deserialize, opts ...clientv3.OpOption) (c Client, err error)

type Deserialize

type Deserialize func(data []byte) (value interface{}, err error)
var (
	DefaultJsonMapDeserialize Deserialize = func(data []byte) (value interface{}, err error) {
		var val map[string]interface{}
		err = jsoniter.Unmarshal(data, &val)
		return val, err
	}

	DefaultYamlMapDeserialize Deserialize = func(data []byte) (value interface{}, err error) {
		var val map[string]interface{}
		err = yaml.Unmarshal(data, &val)
		return val, err
	}

	DefaultStringDeserialize Deserialize = func(data []byte) (value interface{}, err error) {
		return string(data), nil
	}
)

type Service

type Service interface {
	//注册服务
	Register(serviceTarget string, value string)
	//获取所有服务列表
	Get(serviceTarget string) (list map[string]interface{}, exists bool)
	//随机取一个服务
	RandOne(key string) (value interface{}, exists bool)
	//遍历服务,handler返回true时停止遍历
	Range(key string, handler func(index string, val interface{}) (handled bool))
	Close() (err error)
}

func NewService

func NewService(conf *clientv3.Config, prefix string, deserializers map[string]Deserialize, opts ...clientv3.OpOption) (s Service, err error)

Jump to

Keyboard shortcuts

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