This commit is contained in:
wangchuxiao
2023-06-04 10:56:23 +08:00
parent 37e8dbfb94
commit 7051c06c09
4 changed files with 28 additions and 4 deletions
@@ -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]
}