feature/balance #3

Merged
zhangdeman merged 7 commits from feature/balance into master 2021-11-22 19:13:50 +08:00
2 changed files with 32 additions and 1 deletions
Showing only changes of commit ffccdeffd4 - Show all commits

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
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")
}