make load balancing policy name string case-insensitive (#1708)

This commit is contained in:
lyuxuan 2017-12-04 14:03:22 -08:00 committed by GitHub
parent cd563b81ec
commit be077907e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -23,6 +23,7 @@ package balancer
import (
"errors"
"net"
"strings"
"golang.org/x/net/context"
"google.golang.org/grpc/connectivity"
@ -36,15 +37,17 @@ var (
)
// Register registers the balancer builder to the balancer map.
// b.Name will be used as the name registered with this builder.
// b.Name (lowercased) will be used as the name registered with
// this builder.
func Register(b Builder) {
m[b.Name()] = b
m[strings.ToLower(b.Name())] = b
}
// Get returns the resolver builder registered with the given name.
// Note that the compare is done in a case-insenstive fashion.
// If no builder is register with the name, nil will be returned.
func Get(name string) Builder {
if b, ok := m[name]; ok {
if b, ok := m[strings.ToLower(name)]; ok {
return b
}
return nil

View File

@ -689,7 +689,7 @@ func (cc *ClientConn) switchBalancer(name string) {
return
}
if cc.curBalancerName == name {
if strings.ToLower(cc.curBalancerName) == strings.ToLower(name) {
return
}