Documentation ¶
Index ¶
- Constants
- Variables
- type EtcdClient
- func (c *EtcdClient) Close()
- func (c *EtcdClient) DeleteKey(ctx context.Context, name string) error
- func (c *EtcdClient) FormatKey(name string) string
- func (c *EtcdClient) GetKey(ctx context.Context, name string) ([]byte, error)
- func (c *EtcdClient) GetLeaseTTL(ctx context.Context, leaseId int64) (int, error)
- func (c *EtcdClient) GetNode(ctx context.Context, name string) (*Node, error)
- func (c *EtcdClient) GrantLease(ctx context.Context, ttl int32) (int64, error)
- func (c *EtcdClient) Init(parentCtx context.Context) error
- func (c *EtcdClient) IsNodeExist(ctx context.Context, name string) (bool, error)
- func (c *EtcdClient) KeepAlive(ctx context.Context, stopChan chan struct{}, leaseId int64) error
- func (c *EtcdClient) ListNodes(ctx context.Context, prefix string) ([]Node, error)
- func (c *EtcdClient) PutNode(ctx context.Context, name string, value any, leaseId int64) error
- func (c *EtcdClient) RegisterAndKeepAliveForever(ctx context.Context, name string, value any, ttl int32) (*NodeKeepAliveContext, error)
- func (c *EtcdClient) RegisterNode(rootCtx context.Context, name string, value any, ttl int32) (int64, error)
- func (c *EtcdClient) RevokeKeepAlive(ctx context.Context, regCtx *NodeKeepAliveContext) error
- func (c *EtcdClient) RevokeLease(ctx context.Context, leaseId int64) error
- func (c *EtcdClient) SetVerbose(v int32)
- func (c *EtcdClient) WatchDir(ctx context.Context, dir string) <-chan *NodeEvent
- func (c *EtcdClient) WatchDirTo(ctx context.Context, dir string, nodeMap *NodeMap)
- type Node
- func (n *Node) Clone() Node
- func (n *Node) GetBool(key string) bool
- func (n *Node) GetFloat(key string) float64
- func (n *Node) GetInt(key string) int
- func (n *Node) GetStr(key string) string
- func (n *Node) Set(key string, val any)
- func (n *Node) SetBool(key string, val bool)
- func (n *Node) SetFloat(key string, val float64)
- func (n *Node) SetInt(key string, val int)
- func (n *Node) SetStr(key, val string)
- func (n *Node) String() string
- type NodeEvent
- type NodeEventType
- type NodeKeepAliveContext
- type NodeMap
- func (m *NodeMap) AddNode(node Node)
- func (m *NodeMap) Clear()
- func (m *NodeMap) Count() int
- func (m *NodeMap) CountOf(nodeType string) int
- func (m *NodeMap) DeleteNode(nodeType string, id uint32)
- func (m *NodeMap) DeleteNodesOf(nodeType string)
- func (m *NodeMap) FindNodeOf(nodeType string, id uint32) int
- func (m *NodeMap) GetKeys() []string
- func (m *NodeMap) GetNodes(nodeType string) []Node
- func (m *NodeMap) String() string
Constants ¶
View Source
const ( EventChanCapacity = 1024 OpTimeout = 5 VerboseLv1 = 1 VerboseLv2 = 2 )
Variables ¶
Functions ¶
This section is empty.
Types ¶
type EtcdClient ¶
type EtcdClient struct {
// contains filtered or unexported fields
}
EtcdClient 基于etcd的服务发现
func NewEtcdClient ¶
func NewEtcdClient(endpoints, namespace, username, passwd string) *EtcdClient
func (*EtcdClient) Close ¶
func (c *EtcdClient) Close()
func (*EtcdClient) DeleteKey ¶ added in v1.0.10
func (c *EtcdClient) DeleteKey(ctx context.Context, name string) error
DeleteKey 删除一个key
func (*EtcdClient) FormatKey ¶
func (c *EtcdClient) FormatKey(name string) string
func (*EtcdClient) GetLeaseTTL ¶
func (*EtcdClient) GrantLease ¶
GrantLease 申请一个lease
func (*EtcdClient) IsNodeExist ¶
IsNodeExist 节点是否存在
func (*EtcdClient) KeepAlive ¶
func (c *EtcdClient) KeepAlive(ctx context.Context, stopChan chan struct{}, leaseId int64) error
KeepAlive lease保活,当lease撤销时此stopChan被激活
func (*EtcdClient) RegisterAndKeepAliveForever ¶
func (c *EtcdClient) RegisterAndKeepAliveForever(ctx context.Context, name string, value any, ttl int32) (*NodeKeepAliveContext, error)
RegisterAndKeepAliveForever 注册一个节点,并永久保活
func (*EtcdClient) RegisterNode ¶
func (c *EtcdClient) RegisterNode(rootCtx context.Context, name string, value any, ttl int32) (int64, error)
RegisterNode 注册一个节点信息,并返回一个ttl秒的lease
func (*EtcdClient) RevokeKeepAlive ¶
func (c *EtcdClient) RevokeKeepAlive(ctx context.Context, regCtx *NodeKeepAliveContext) error
func (*EtcdClient) RevokeLease ¶
func (c *EtcdClient) RevokeLease(ctx context.Context, leaseId int64) error
RevokeLease 撤销一个lease
func (*EtcdClient) SetVerbose ¶
func (c *EtcdClient) SetVerbose(v int32)
func (*EtcdClient) WatchDir ¶
func (c *EtcdClient) WatchDir(ctx context.Context, dir string) <-chan *NodeEvent
WatchDir 订阅目录下的节点变化
func (*EtcdClient) WatchDirTo ¶
func (c *EtcdClient) WatchDirTo(ctx context.Context, dir string, nodeMap *NodeMap)
WatchDirTo 订阅目录下的所有节点变化, 并把节点变化更新到nodeMap
type Node ¶
type Node struct { Type string `json:"type"` ID uint32 `json:"id"` Status uint32 `json:"status,omitempty"` PID int `json:"pid,omitempty"` Host string `json:"host,omitempty"` Interface string `json:"interface,omitempty"` URI string `json:"uri,omitempty"` Args map[string]string `json:"args,omitempty"` }
Node 表示用于服务发现的节点信息
type NodeEventType ¶
type NodeEventType int
const ( EventUnknown NodeEventType = 0 EventCreate NodeEventType = 1 EventUpdate NodeEventType = 2 EventDelete NodeEventType = 3 )
func (NodeEventType) String ¶
func (e NodeEventType) String() string
type NodeKeepAliveContext ¶
type NodeKeepAliveContext struct { LeaseId int64 LeaseAlive atomic.Bool TTL int32 Name string Value any // contains filtered or unexported fields }
NodeKeepAliveContext 用于注册并保活节点
func NewNodeKeepAliveContext ¶
func NewNodeKeepAliveContext(name string, value any, ttl int32) *NodeKeepAliveContext
type NodeMap ¶
NodeMap 按服务类型区分的节点信息
func NewNodeMap ¶
func NewNodeMap() *NodeMap
func (*NodeMap) DeleteNode ¶
DeleteNode 删除一个节点
func (*NodeMap) DeleteNodesOf ¶ added in v1.0.4
DeleteNodesOf 删除某一类型的所有节点
func (*NodeMap) FindNodeOf ¶ added in v1.0.4
Click to show internal directories.
Click to hide internal directories.