package balancer import "sync/atomic" type roundRobin struct { counter atomic.Uint64 } // RoundRobin returns a strategy that cycles through healthy endpoints // sequentially using an atomic counter. func RoundRobin() Strategy { return &roundRobin{} } func (r *roundRobin) Next(healthy []Endpoint) (Endpoint, error) { if len(healthy) == 0 { return Endpoint{}, ErrNoHealthy } idx := r.counter.Add(1) - 1 return healthy[idx%uint64(len(healthy))], nil }