Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client interface {
// Put 存储键值对
Put(ctx context.Context, key, value string, opts ...interface{}) error
// Get 获取键值
Get(ctx context.Context, key string, opts ...interface{}) (string, error)
// Delete 删除键
Delete(ctx context.Context, key string, opts ...interface{}) error
// List 列出指定前缀的所有键值对
List(ctx context.Context, prefix string, opts ...interface{}) (map[string]string, error)
// Watch 监听键变化
Watch(ctx context.Context, key string, opts ...interface{}) (<-chan WatchEvent, error)
// Register 服务注册
Register(ctx context.Context, serviceKey, serviceValue string, ttl int64) error
// Unregister 服务注销
Unregister(ctx context.Context, serviceKey string) error
// Discover 服务发现
Discover(ctx context.Context, servicePrefix string) ([]ServiceEndpoint, error)
// Close 关闭客户端
Close() error
}
Client etcd客户端接口
func NewClientFromConfig ¶
func NewClientFromConfig(cfg *config.ETCDConfig) (Client, error)
NewClientFromConfig 从配置创建etcd客户端
func NewEtcdV3Client ¶
func NewEtcdV3Client(config *ClientConfig) (Client, error)
NewEtcdV3Client 创建etcd v3客户端
type ClientConfig ¶
type ClientConfig struct {
Endpoints []string
Username string
Password string
Namespace string
DialTimeout time.Duration
Timeout time.Duration
TLS *tls.Config
}
ClientConfig etcd客户端配置
type ServiceEndpoint ¶
type ServiceEndpoint struct {
Address string `json:"address"`
Port int `json:"port"`
Meta map[string]string `json:"meta"`
}
ServiceEndpoint 服务端点
type WatchEvent ¶
type WatchEvent struct {
Type WatchEventType
Key string
Value string
}
WatchEvent 监听事件
type WatchEventType ¶
type WatchEventType int
WatchEventType 监听事件类型
const ( WatchEventTypePut WatchEventType = iota WatchEventTypeDelete )
Click to show internal directories.
Click to hide internal directories.