所谓的轮询
,就是挨个访问。
//负载均衡类
type LoadBalance struct{
Servers []*HttpServer
//指向当前访问的服务器
CurIndex int //添加这个变量
}
轮询算法实现:
//轮询算法
func (this *LoadBalance) RoundRobin() *HttpServer {
server := this.Servers[this.CurIndex]
this.CurIndex = (this.CurIndex + 1) % len(this.Servers)
return server
}