32 lines
557 B
Go
32 lines
557 B
Go
package balance
|
|
|
|
import (
|
|
"hpds_control_center/model"
|
|
"math/rand"
|
|
)
|
|
|
|
// RandomBalance 随机负载均衡
|
|
type RandomBalance struct {
|
|
curIndex int
|
|
|
|
rss []*model.NodeLastStateItem
|
|
}
|
|
|
|
func (r *RandomBalance) Add(params model.NodeLastStateItem) error {
|
|
r.rss = append(r.rss, ¶ms)
|
|
|
|
return nil
|
|
}
|
|
|
|
func (r *RandomBalance) Next() *model.NodeLastStateItem {
|
|
if len(r.rss) == 0 {
|
|
return nil
|
|
}
|
|
r.curIndex = rand.Intn(len(r.rss))
|
|
return r.rss[r.curIndex]
|
|
}
|
|
|
|
func (r *RandomBalance) Get(int64) (*model.NodeLastStateItem, error) {
|
|
return r.Next(), nil
|
|
}
|