This commit is contained in:
wangchuxiao
2023-06-04 11:00:39 +08:00
parent 7051c06c09
commit a3055f53af
2 changed files with 6 additions and 3 deletions
@@ -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
}