From ffccdeffd49fa2d016d4dc7557a9a9813dbdb927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Mon, 22 Nov 2021 16:52:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B4=9F=E8=BD=BD=E7=AE=97?= =?UTF-8?q?=E6=B3=95=E7=9A=84=E6=8E=A5=E5=8F=A3=E7=BA=A6=E6=9D=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- balance/abstract.go | 30 ++++++++++++++++++++++++++++++ balance/poll.go | 3 ++- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 balance/abstract.go 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") }