增加移除节点/增加节点/查询节点列表的方法
This commit is contained in:
parent
75b557b07f
commit
bd32998c76
@ -74,3 +74,57 @@ func (p *Poll) GetServerNode() (*define.ServerNode, error) {
|
||||
|
||||
return serverNode, nil
|
||||
}
|
||||
|
||||
// AddServerNode 新添加一个服务器节点
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 10:07 下午 2021/10/20
|
||||
func (p *Poll) AddServerNode(hostIP string, port int) error {
|
||||
if len(hostIP) == 0 || port <= 0 {
|
||||
return errors.New("host ip or port is invalid")
|
||||
}
|
||||
p.Lock()
|
||||
defer p.Unlock()
|
||||
for _, item := range p.serverList {
|
||||
if item.HostIP == hostIP && item.Port == port {
|
||||
return errors.New("host config is already exist")
|
||||
}
|
||||
}
|
||||
p.serverList = append(p.serverList, &define.ServerNode{
|
||||
HostIP: hostIP,
|
||||
Port: port,
|
||||
Status: define.ServerNodeStatusNormal,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
// Remove 移除一个节点, force = true , 强制删除, force = false 逻辑删除, 设置状态
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 10:19 下午 2021/10/20
|
||||
func (p *Poll) Remove(hostIP string, port int, force bool) {
|
||||
p.Lock()
|
||||
defer p.Unlock()
|
||||
tmpServerNode := make([]*define.ServerNode, 0)
|
||||
for _, item := range p.serverList {
|
||||
if item.HostIP == hostIP && item.Port == port {
|
||||
if force {
|
||||
continue
|
||||
}
|
||||
item.Status = define.ServerNodeStatusRemove
|
||||
}
|
||||
tmpServerNode = append(tmpServerNode, item)
|
||||
}
|
||||
p.serverList = tmpServerNode
|
||||
}
|
||||
|
||||
// GetServerNodeList 获取服务器节点
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 10:33 下午 2021/10/20
|
||||
func (p *Poll) GetServerNodeList() []*define.ServerNode {
|
||||
return p.serverList
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user