github.com/moleculer-go/moleculer@v0.3.3/strategy/round-robin.go (about) 1 package strategy 2 3 // RoundRobinStrategy exposes the type as a strategy option 4 type RoundRobinStrategy struct { 5 counter int 6 } 7 8 func NewRoundRobinStrategy() Strategy { 9 return &RoundRobinStrategy{counter: -1} 10 } 11 12 func (roundRobinStrategy *RoundRobinStrategy) Select(nodes []Selector) *Selector { 13 if len(nodes) == 0 { 14 return nil 15 } 16 17 roundRobinStrategy.counter++ 18 19 if roundRobinStrategy.counter >= len(nodes) { 20 roundRobinStrategy.counter = 0 21 } 22 23 return &nodes[roundRobinStrategy.counter] 24 }