diff --git a/grpc.go b/grpc.go index b3473ef..f92048f 100644 --- a/grpc.go +++ b/grpc.go @@ -22,6 +22,7 @@ import ( "github.com/micro/go-micro/util/addr" mgrpc "github.com/micro/go-micro/util/grpc" "github.com/micro/go-micro/util/log" + mnet "github.com/micro/go-micro/util/net" "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -519,15 +520,12 @@ func (g *grpcServer) Register() error { advt = config.Address } - if idx := strings.Count(advt, ":"); idx > 1 { + if cnt := strings.Count(advt, ":"); cnt >= 1 { // ipv6 address in format [host]:port or ipv4 host:port host, port, err = net.SplitHostPort(advt) if err != nil { return err } - if host == "::" { - host = fmt.Sprintf("[%s]", host) - } } else { host = advt } @@ -540,7 +538,7 @@ func (g *grpcServer) Register() error { // register service node := ®istry.Node{ Id: config.Name + "-" + config.Id, - Address: fmt.Sprintf("%s:%s", addr, port), + Address: mnet.HostPort(addr, port), Metadata: config.Metadata, } @@ -649,15 +647,12 @@ func (g *grpcServer) Deregister() error { advt = config.Address } - if idx := strings.Count(advt, ":"); idx > 1 { + if cnt := strings.Count(advt, ":"); cnt >= 1 { // ipv6 address in format [host]:port or ipv4 host:port host, port, err = net.SplitHostPort(advt) if err != nil { return err } - if host == "::" { - host = fmt.Sprintf("[%s]", host) - } } else { host = advt } @@ -669,7 +664,7 @@ func (g *grpcServer) Deregister() error { node := ®istry.Node{ Id: config.Name + "-" + config.Id, - Address: fmt.Sprintf("%s:%s", addr, port), + Address: mnet.HostPort(addr, port), } service := ®istry.Service{