bunch of other ipv6 fixes

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2019-07-18 00:18:40 +03:00
parent 5aad839816
commit c0e32da83e

15
grpc.go
View File

@ -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 := &registry.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 := &registry.Node{
Id: config.Name + "-" + config.Id,
Address: fmt.Sprintf("%s:%s", addr, port),
Address: mnet.HostPort(addr, port),
}
service := &registry.Service{