|
|
|
@ -11,7 +11,10 @@ type RoundRobin struct {
|
|
|
|
|
lock sync.Mutex
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *RoundRobin) getConnBalance(conns []*grpc.ClientConn) (conn *grpc.ClientConn) {
|
|
|
|
|
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 {
|
|
|
|
@ -19,5 +22,5 @@ func (r *RoundRobin) getConnBalance(conns []*grpc.ClientConn) (conn *grpc.Client
|
|
|
|
|
} else {
|
|
|
|
|
r.index = 0
|
|
|
|
|
}
|
|
|
|
|
return conns[r.index]
|
|
|
|
|
return conns[r.index], nil
|
|
|
|
|
}
|
|
|
|
|