From be077907e29fdb945d351e4284eb5361e7f8924e Mon Sep 17 00:00:00 2001 From: lyuxuan Date: Mon, 4 Dec 2017 14:03:22 -0800 Subject: [PATCH] make load balancing policy name string case-insensitive (#1708) --- balancer/balancer.go | 9 ++++++--- clientconn.go | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/balancer/balancer.go b/balancer/balancer.go index 8bdfe069b..a6278ca1c 100644 --- a/balancer/balancer.go +++ b/balancer/balancer.go @@ -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 diff --git a/clientconn.go b/clientconn.go index f058d3716..4a98265a0 100644 --- a/clientconn.go +++ b/clientconn.go @@ -689,7 +689,7 @@ func (cc *ClientConn) switchBalancer(name string) { return } - if cc.curBalancerName == name { + if strings.ToLower(cc.curBalancerName) == strings.ToLower(name) { return }