goetcd

package
v1.2.173 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

README

golang operation etcd api

需要实现通过etcd 访问 rpc server服务,不用在go zero 中配置 ---- ing

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Del

func Del(key string) (resp *clientv3.DeleteResponse, err error)

func DelClient added in v1.2.108

func DelClient(names ...string)

func DelWithPrefix

func DelWithPrefix(key string) (resp *clientv3.DeleteResponse, err error)

func Exists added in v1.2.107

func Exists(key string, opts ...clientv3.OpOption) (bool, error)

func Get

func Get(key string, opts ...clientv3.OpOption) (rsp *clientv3.GetResponse, err error)

func GetArray

func GetArray(key string) (data []string)

func GetMap

func GetMap(key string) (data map[string]string)

func GetString

func GetString(key string) string

func Init

func Init(configs ...Config) (err error)

func RegisterService

func RegisterService(key, val string) (err error)

func Set

func Set(key, val string) (resp *clientv3.PutResponse, err error)

func SetTTL

func SetTTL(key, val string, ttl int64) (resp *clientv3.PutResponse, err error)

func SetTTLWithPrevKV

func SetTTLWithPrevKV(key, val string, ttl int64) (resp *clientv3.PutResponse, err error)

func SetWithPrevKV

func SetWithPrevKV(key, val string) (resp *clientv3.PutResponse, err error)

func Watch

func Watch(key string) <-chan []string

Types

type Config

type Config struct {
	Endpoints []string `json:"endpoints,optional"  yaml:"Endpoints"`
	Name      string   `json:"name,optional"  yaml:"Name"`
	Username  string   `json:"username,optional"  yaml:"Username"`
	Password  string   `json:"password,optional"  yaml:"Password"`
	TLS       *TLS     `json:"tls,optional"  yaml:"TLS"`
}

type GoEtcdClient

type GoEtcdClient struct {
	*clientv3.Client
	// contains filtered or unexported fields
}

func Default

func Default() *GoEtcdClient

func GetClient

func GetClient(names ...string) *GoEtcdClient

func New

func New(conf Config) (cli *GoEtcdClient, err error)

func (*GoEtcdClient) CheckRpcServices added in v1.2.94

func (cli *GoEtcdClient) CheckRpcServices(rpcServices []string) bool

检测 rpc服务是否启动

func (*GoEtcdClient) Del

func (cli *GoEtcdClient) Del(key string, opts ...clientv3.OpOption) (resp *clientv3.DeleteResponse, err error)

del key and return previous key-value

func (*GoEtcdClient) DelWithPrefix

func (cli *GoEtcdClient) DelWithPrefix(key string) (resp *clientv3.DeleteResponse, err error)

del prefix key and return previous key-value

func (*GoEtcdClient) Get

func (cli *GoEtcdClient) Get(key string, opts ...clientv3.OpOption) (resp *clientv3.GetResponse, err error)

get value by key

func (*GoEtcdClient) GetArray

func (cli *GoEtcdClient) GetArray(key string) (data []string)

get array value by prefix key

func (*GoEtcdClient) GetMap

func (cli *GoEtcdClient) GetMap(key string) (data map[string]string)

get map value by prefix key

func (*GoEtcdClient) GetString

func (cli *GoEtcdClient) GetString(key string) string

get string value by prefix key

func (*GoEtcdClient) RegisterService

func (cli *GoEtcdClient) RegisterService(serviceName, addr string) (err error)

register service and keepalive

func (*GoEtcdClient) Set

func (cli *GoEtcdClient) Set(key, val string, opts ...clientv3.OpOption) (resp *clientv3.PutResponse, err error)

set key-value

func (*GoEtcdClient) SetTTL

func (cli *GoEtcdClient) SetTTL(key, val string, ttl int64, opts ...clientv3.OpOption) (resp *clientv3.PutResponse, err error)

set key-value-ttl

func (*GoEtcdClient) SetTTLWithPrevKV

func (cli *GoEtcdClient) SetTTLWithPrevKV(key, val string, ttl int64) (resp *clientv3.PutResponse, err error)

set key-value-ttl and return previous key-value

func (*GoEtcdClient) SetWithPrevKV

func (cli *GoEtcdClient) SetWithPrevKV(key, val string) (resp *clientv3.PutResponse, err error)

set key-value and return previous key-value

func (*GoEtcdClient) Watch

func (cli *GoEtcdClient) Watch(key string) <-chan []string

watch the key

type TLS

type TLS struct {
	CertFile string `json:"certFile,optional"  yaml:"CertFile"`
	KeyFile  string `json:"keyFile,optional"  yaml:"KeyFile"`
	CAFile   string `json:"caFile,optional"  yaml:"CAFile"`
}

Jump to

Keyboard shortcuts

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