etcdx

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultDialTimout 默认连接超时时间
	DefaultDialTimout = 10 * time.Second
)

Variables

View Source
var (
	// DefaultMetaData 默认元数据
	DefaultMetaData = &MetaData{
		Network: "http",
	}
)
View Source
var ErrorNotFound = errors.New("not found")

ErrorNotFound 表示该key找不多对应的值,即不存在

Functions

This section is empty.

Types

type ChangeHandler

type ChangeHandler func(key string, value []byte)

ChangeHandler 发生变化的函数

type ClientX

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

ClientX 是封装的Etcd客户端操作

func New

func New(etcdGateway []string) (*ClientX, error)

New 新建一个ClientX实例

func (*ClientX) Delete

func (c *ClientX) Delete(ctx context.Context, key string) error

Delete 删除一个指定的键

func (*ClientX) DialGrpc

func (c *ClientX) DialGrpc(service string, opts ...grpc.DialOption) (*grpc.ClientConn, error)

DialGrpc 使用gRpc的负载均很获取grpc连接

func (*ClientX) Get

func (c *ClientX) Get(ctx context.Context, key string) ([]byte, error)

Get 获取一个键值对

func (*ClientX) GetWithPrefix

func (c *ClientX) GetWithPrefix(ctx context.Context, key string) ([][]byte, error)

GetWithPrefix 前缀获取一组键值,找不到 ErrorNotFound

func (*ClientX) Put

func (c *ClientX) Put(ctx context.Context, key, value string) error

Put 设置一个键值对

func (*ClientX) Watch

func (c *ClientX) Watch(ctx context.Context, key string, putHandler ChangeHandler, delHandler ChangeHandler)

Watch 监听指定键的变化

func (*ClientX) WatchWithPrefix

func (c *ClientX) WatchWithPrefix(ctx context.Context, key string, putHandler ChangeHandler, delHandler ChangeHandler)

WatchWithPrefix 监听某一组简直对的变化

type MetaData

type MetaData struct {
	Network string `json:"Network"`
}

MetaData 元数据结构

type ServiceManager

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

ServiceManager 服务节点管理器

func NewServiceManager

func NewServiceManager(xClient *ClientX, target string, leaseTTl int64, heartT int) (*ServiceManager, error)

NewServiceManager 增加服务节点管理器

func (*ServiceManager) Destory

func (s *ServiceManager) Destory(addr string) error

Destory 销毁

func (*ServiceManager) List added in v0.1.3

func (s *ServiceManager) List() (map[string]endpoints.Endpoint, error)

List 获取当前target的所有节点

func (*ServiceManager) PushEndpoint added in v0.1.2

func (s *ServiceManager) PushEndpoint(addr string, metadata interface{}) error

PushEndpoint push节点数据

func (*ServiceManager) Register

func (s *ServiceManager) Register(addr string, metadate ...interface{}) error

Register 注册到节点

func (*ServiceManager) Watch added in v0.1.3

func (s *ServiceManager) Watch(h func(key string, ep endpoints.Endpoint)) error

Watch 检查数据的变更

Jump to

Keyboard shortcuts

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