Ai
1 Star 0 Fork 0

叶明志/golang练习

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
roundrobin.go 405 Bytes
一键复制 编辑 原始数据 按行查看 历史
yemingzhi 提交于 2019-07-07 00:35 +08:00 . 负载均衡balance库的修改
package balance
import(
"errors"
)
type RoundRobinBalance struct{
curIndex int
}
func init(){
RegisterBalancer("roundrobin",&RoundRobinBalance{})
}
func (p *RoundRobinBalance)DoBalance(insts []*Instance,key ...string) (inst *Instance, err error) {
if len(insts)==0 {
err= errors.New("No instance")
return
}
lens:=len(insts)
inst=insts[p.curIndex]
p.curIndex=(p.curIndex+1)%lens
return
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/yemingzhi/GolangLearnPractice1.git
git@gitee.com:yemingzhi/GolangLearnPractice1.git
yemingzhi
GolangLearnPractice1
golang练习
2bf136849dce

搜索帮助