标签:ble pack display tom app 算法 append order mat
package util
import (
"math/rand"
"time"
)
type LoadBalance struct {
Servers []*ServiceInfo
}
func NewloadBalance(servers []*ServiceInfo) *LoadBalance {
return &LoadBalance{Servers:servers}
}
func(this *LoadBalance) getByRand(sname string ) *ServiceInfo{
tmp:=make([]*ServiceInfo,0)
for _,service:=range this.Servers{
if service.ServiceName==sname{
tmp=append(tmp,service)
}
}
if len(tmp)==0 {
return nil
}
rand.Seed(time.Now().UnixNano())
i:=rand.Intn(len(tmp)-1)
return this.Servers[i]
}
标签:ble pack display tom app 算法 append order mat
原文地址:https://www.cnblogs.com/hualou/p/12071073.html