增加负载算法的接口约束

This commit is contained in:
白茶清欢 2021-11-22 16:52:08 +08:00
parent 30059c0341
commit ffccdeffd4
2 changed files with 32 additions and 1 deletions

30
balance/abstract.go Normal file
View File

@ -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
}

View File

@ -8,6 +8,7 @@
package balance package balance
import ( import (
"net/http"
"sync" "sync"
"git.zhangdeman.cn/zhangdeman/gopkg/balance/define" "git.zhangdeman.cn/zhangdeman/gopkg/balance/define"
@ -48,7 +49,7 @@ type Poll struct {
// Author : go_developer@163.com<白茶清欢> // Author : go_developer@163.com<白茶清欢>
// //
// Date : 12:43 下午 2021/10/19 // 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 { if len(p.serverList) == 0 {
return nil, errors.New("server list is empty") return nil, errors.New("server list is empty")
} }