mirror of https://github.com/grpc/grpc-go.git
make load balancing policy name string case-insensitive (#1708)
This commit is contained in:
parent
cd563b81ec
commit
be077907e2
|
@ -23,6 +23,7 @@ package balancer
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"net"
|
"net"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
"google.golang.org/grpc/connectivity"
|
"google.golang.org/grpc/connectivity"
|
||||||
|
@ -36,15 +37,17 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Register registers the balancer builder to the balancer map.
|
// 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) {
|
func Register(b Builder) {
|
||||||
m[b.Name()] = b
|
m[strings.ToLower(b.Name())] = b
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get returns the resolver builder registered with the given name.
|
// 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.
|
// If no builder is register with the name, nil will be returned.
|
||||||
func Get(name string) Builder {
|
func Get(name string) Builder {
|
||||||
if b, ok := m[name]; ok {
|
if b, ok := m[strings.ToLower(name)]; ok {
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -689,7 +689,7 @@ func (cc *ClientConn) switchBalancer(name string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if cc.curBalancerName == name {
|
if strings.ToLower(cc.curBalancerName) == strings.ToLower(name) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue