From c0e32da83e9f40623d5776e7d9c90d55d0649fd2 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 18 Jul 2019 00:18:40 +0300 Subject: [PATCH] bunch of other ipv6 fixes Signed-off-by: Vasiliy Tolstov --- grpc.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) 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{