35 lines
655 B
Go
35 lines
655 B
Go
package balance
|
|
|
|
import (
|
|
"hpds_control_center/model"
|
|
)
|
|
|
|
// RoundRobinBalance 轮询负载均衡
|
|
type RoundRobinBalance struct {
|
|
curIndex int
|
|
rss []*model.NodeLastStateItem
|
|
}
|
|
|
|
func (r *RoundRobinBalance) Add(params model.NodeLastStateItem) error {
|
|
r.rss = append(r.rss, ¶ms)
|
|
return nil
|
|
}
|
|
|
|
func (r *RoundRobinBalance) Next() *model.NodeLastStateItem {
|
|
if len(r.rss) == 0 {
|
|
return nil
|
|
}
|
|
lens := len(r.rss)
|
|
if r.curIndex >= lens {
|
|
r.curIndex = 0
|
|
}
|
|
|
|
curNode := r.rss[r.curIndex]
|
|
r.curIndex = (r.curIndex + 1) % lens
|
|
return curNode
|
|
}
|
|
|
|
func (r *RoundRobinBalance) Get(int64) (*model.NodeLastStateItem, error) {
|
|
return r.Next(), nil
|
|
}
|