当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
55 Star 265 Fork 97

fagongzi / gateway
暂停

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
roundrobin.go 548 Bytes
一键复制 编辑 原始数据 按行查看 历史
张旭 提交于 2017-06-28 08:47 . dev: use LF
package lb
import (
"container/list"
"sync/atomic"
"github.com/valyala/fasthttp"
)
// RoundRobin round robin loadBalance impl
type RoundRobin struct {
ops *uint64
}
// NewRoundRobin create a RoundRobin
func NewRoundRobin() LoadBalance {
var ops uint64
ops = 0
return RoundRobin{
ops: &ops,
}
}
// Select select a server from servers using RoundRobin
func (rr RoundRobin) Select(req *fasthttp.Request, servers *list.List) int {
l := uint64(servers.Len())
if 0 >= l {
return -1
}
return int(atomic.AddUint64(rr.ops, 1) % l)
}
Go
1
https://gitee.com/fagongzi/gateway.git
git@gitee.com:fagongzi/gateway.git
fagongzi
gateway
gateway
v2.5.1

搜索帮助