diff --git a/balance/abstract.go b/balance/abstract.go new file mode 100644 index 0000000..1275f69 --- /dev/null +++ b/balance/abstract.go @@ -0,0 +1,30 @@ +// Package balance... +// +// Description : balance... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 2021-11-22 4:45 下午 +package balance + +import ( + "net/http" + + "git.zhangdeman.cn/zhangdeman/gopkg/balance/define" +) + +// IBalance 负载算法接口约束 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 4:45 下午 2021/11/22 +type IBalance interface { + // GetServerNode 获取一个服务器节点 + GetServerNode(req *http.Request) (*define.ServerNode, error) + // AddServerNode 新增一个服务器节点 + AddServerNode(hostIP string, port int) error + // Remove 移除一个节点 + Remove(hostIP string, port int, force bool) + // GetServerNodeList 获取服务节点列表 + GetServerNodeList() []*define.ServerNode +} diff --git a/balance/poll.go b/balance/poll.go index c89eac8..62337d7 100644 --- a/balance/poll.go +++ b/balance/poll.go @@ -8,6 +8,7 @@ package balance import ( + "net/http" "sync" "git.zhangdeman.cn/zhangdeman/gopkg/balance/define" @@ -48,7 +49,7 @@ type Poll struct { // Author : go_developer@163.com<白茶清欢> // // Date : 12:43 下午 2021/10/19 -func (p *Poll) GetServerNode() (*define.ServerNode, error) { +func (p *Poll) GetServerNode(req *http.Request) (*define.ServerNode, error) { if len(p.serverList) == 0 { return nil, errors.New("server list is empty") }