parent
37e8dbfb94
commit
7051c06c09
@ -0,0 +1,23 @@
|
||||
package zookeeper
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type RoundRobin struct {
|
||||
index int
|
||||
lock sync.Mutex
|
||||
}
|
||||
|
||||
func (r *RoundRobin) getConnBalance(conns []*grpc.ClientConn) (conn *grpc.ClientConn) {
|
||||
r.lock.Lock()
|
||||
defer r.lock.Unlock()
|
||||
if r.index < len(conns)-1 {
|
||||
r.index++
|
||||
} else {
|
||||
r.index = 0
|
||||
}
|
||||
return conns[r.index]
|
||||
}
|
Loading…
Reference in new issue