discovery

package
v0.6.9 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2022 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventChanCapacity = 1000
	OpTimeout         = 3

	VerboseLv1 = 1
	VerboseLv2 = 2
)
View Source
const (
	NODE_KEY_ID        = "ID"
	NODE_KEY_TYPE      = "Type"
	NODE_KEY_INTERFACE = "Interface"
	NODE_KEY_PID       = "PID"
	NODE_KEY_HOST      = "Host"
)

Variables

View Source
var (
	ErrEmptyLeasePointer   = errors.New("empty lease pointer")
	ErrNodeKeyAlreadyExist = errors.New("node key already exist")
	ErrNoKeyDeleted        = errors.New("no key deleted")
)

Functions

This section is empty.

Types

type Client

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

基于etcd的服务发现

func NewClient

func NewClient(hostAddr, namespace string) *Client

func (*Client) Close

func (c *Client) Close()

func (*Client) DelKey

func (c *Client) DelKey(ctx context.Context, name string) error

删除一个key

func (*Client) GetLeaseTTL

func (c *Client) GetLeaseTTL(ctx context.Context, leaseId int64) (int, error)

func (*Client) GetNode

func (c *Client) GetNode(ctx context.Context, name string) (Node, error)

获取节点信息

func (*Client) GrantLease

func (c *Client) GrantLease(ctx context.Context, ttl int) (int64, error)

申请一个lease

func (*Client) Init

func (c *Client) Init() error

func (*Client) IsClosing

func (c *Client) IsClosing() bool

func (*Client) IsNodeExist

func (c *Client) IsNodeExist(ctx context.Context, name string) (bool, error)

节点是否存在

func (*Client) KeepAlive

func (c *Client) KeepAlive(ctx context.Context, stopChan chan struct{}, leaseId int64) error

lease保活,当lease撤销时此stopChan被激活

func (*Client) ListDir

func (c *Client) ListDir(ctx context.Context, dir string) ([]Node, error)

列出目录下的所有节点

func (*Client) PutNode

func (c *Client) PutNode(ctx context.Context, name string, value interface{}, leaseId int64) error

设置节点信息

func (*Client) RegisterAndKeepAliveForever

func (c *Client) RegisterAndKeepAliveForever(ctx context.Context, name string, value interface{}, ttl int) (*NodeKeepAliveContext, error)

注册一个节点,并永久保活

func (*Client) RegisterNode

func (c *Client) RegisterNode(rootCtx context.Context, name string, value interface{}, ttl int) (int64, error)

注册一个节点信息,并返回一个ttl秒的lease

func (*Client) RevokeKeepAlive added in v0.1.4

func (c *Client) RevokeKeepAlive(ctx context.Context, regCtx *NodeKeepAliveContext) error

func (*Client) RevokeLease

func (c *Client) RevokeLease(ctx context.Context, leaseId int64) error

撤销一个lease

func (*Client) SetVerbose

func (c *Client) SetVerbose(v int32)

func (*Client) WatchDir

func (c *Client) WatchDir(ctx context.Context, dir string) <-chan *NodeEvent

订阅目录下的节点变化

func (*Client) WatchDirTo

func (c *Client) WatchDirTo(ctx context.Context, dir string, nodeMap *NodeMap)

订阅目录下的所有节点变化, 并把节点变化更新到nodeMap

type INode

type INode interface {
	ID() int16
	Type() string
	Interface() string
}

type Node

type Node map[string]interface{}

一个节点信息

func NewNode

func NewNode(nodeType string, id uint16) Node

func (Node) Get

func (n Node) Get(key string) interface{}

func (Node) GetInt

func (n Node) GetInt(key string) int

func (Node) GetStr

func (n Node) GetStr(key string) string

func (Node) ID

func (n Node) ID() uint16

节点ID

func (Node) Interface

func (n Node) Interface() string

节点接口地址

func (Node) Set

func (n Node) Set(key string, val interface{})

func (Node) String

func (n Node) String() string

func (Node) Type

func (n Node) Type() string

节点类型

type NodeEvent

type NodeEvent struct {
	Type NodeEventType
	Key  string
	Node 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 added in v0.1.4

type NodeKeepAliveContext struct {
	LeaseId    int64
	LeaseAlive bool
	Name       string
	Value      interface{}
	TTL        int
	// contains filtered or unexported fields
}

用于注册并保活节点

func NewNodeKeepAliveContext added in v0.1.4

func NewNodeKeepAliveContext(name string, value interface{}, ttl int) *NodeKeepAliveContext

type NodeMap

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

按服务类型区分的节点信息

func NewNodeMap

func NewNodeMap() *NodeMap

func (*NodeMap) Clear

func (m *NodeMap) Clear()

func (*NodeMap) Count

func (m *NodeMap) Count() int

所有节点数量

func (*NodeMap) DeleteNode

func (m *NodeMap) DeleteNode(nodeType string, id uint16)

删除一个节点

func (*NodeMap) DeleteNodes

func (m *NodeMap) DeleteNodes(nodeType string)

删除某一类型的所有节点

func (*NodeMap) GetKeys

func (m *NodeMap) GetKeys() []string

func (*NodeMap) GetNodes

func (m *NodeMap) GetNodes(nodeType string) NodeSet

所有本类型的节点,不要修改返回值

func (*NodeMap) InsertNode

func (m *NodeMap) InsertNode(node Node)

添加一个节点

func (*NodeMap) String

func (m *NodeMap) String() string

type NodeSet

type NodeSet []Node

节点列表

Jump to

Keyboard shortcuts

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