mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
27 lines
410 B
Go
27 lines
410 B
Go
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, err error) {
|
|
if len(conns) == 0 {
|
|
return nil, ErrConnIsNil
|
|
}
|
|
r.lock.Lock()
|
|
defer r.lock.Unlock()
|
|
if r.index < len(conns)-1 {
|
|
r.index++
|
|
} else {
|
|
r.index = 0
|
|
}
|
|
return conns[r.index], nil
|
|
}
|