2021-11-23 11:58:13 +08:00
|
|
|
// Package etcd...
|
|
|
|
//
|
|
|
|
// Description : etcd...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 2021-11-23 11:25 上午
|
|
|
|
package etcd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math"
|
|
|
|
"time"
|
2021-11-23 15:13:50 +08:00
|
|
|
|
|
|
|
"go.etcd.io/etcd/clientv3"
|
2021-11-23 11:58:13 +08:00
|
|
|
)
|
|
|
|
|
2021-11-23 12:31:45 +08:00
|
|
|
// 初始化client各种默认配置
|
2021-11-23 11:58:13 +08:00
|
|
|
const (
|
|
|
|
// DefaultDialTimeout 默认超时时间
|
|
|
|
DefaultDialTimeout = 5 * time.Second
|
|
|
|
// DefaultDialKeepAliveTime 默认ping时间
|
|
|
|
DefaultDialKeepAliveTime = 3 * time.Second
|
|
|
|
// DefaultDialKeepAliveTimeout ping之后等待响应的超时时间, 超时未响应, 连接将会断开
|
|
|
|
DefaultDialKeepAliveTimeout = 5 * time.Second
|
|
|
|
// DefaultMaxCallSendMsgSize 客户端请求体最大字节数, 默认 2M , 和etcd默认值保持一致
|
|
|
|
DefaultMaxCallSendMsgSize = 2 * 1024 * 1024
|
|
|
|
// DefaultMaxCallRecvMsgSize 客户端接受的响应题最大大小, 默认int32最大值, 和etcd默认值保持一致
|
|
|
|
DefaultMaxCallRecvMsgSize = math.MaxInt32
|
|
|
|
)
|
2021-11-23 12:31:45 +08:00
|
|
|
|
|
|
|
// 操作过程中各种默认配置
|
|
|
|
const (
|
|
|
|
// DefaultPutTimeout put 默认超时时间
|
|
|
|
DefaultPutTimeout = time.Second
|
|
|
|
// DefaultGetTimeout get 默认超时时间
|
|
|
|
DefaultGetTimeout = time.Second
|
|
|
|
)
|
2021-11-23 15:13:50 +08:00
|
|
|
|
|
|
|
// WatcherHandler 监听key变化的处理函数
|
|
|
|
type WatcherHandler func(event *clientv3.Event)
|
2021-11-23 16:31:25 +08:00
|
|
|
|
|
|
|
// CancelWatcherHandler 取消监听后的处理函数
|
|
|
|
type CancelWatcherHandler func(key string, data interface{})
|
2021-11-23 16:55:05 +08:00
|
|
|
|
|
|
|
// TimeoutWatcherHandler 超时之后的回调函数
|
|
|
|
type TimeoutWatcherHandler func(key string, timeout time.Duration)
|
2021-11-23 20:02:15 +08:00
|
|
|
|
|
|
|
// LeaseKeepALiveHandler 续期成功的处理
|
|
|
|
type LeaseKeepALiveHandler func(key string, leaseDetail *clientv3.LeaseKeepAliveResponse)
|