registry/mdns: fix ipv6 addr in mdns registry

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2020-03-07 21:28:48 +03:00
parent 077063c212
commit 55c19afb0b

View File

@ -148,7 +148,6 @@ func (m *mdnsRegistry) Register(service *Service, opts ...RegisterOption) error
continue
}
//
host, pt, err := net.SplitHostPort(node.Address)
if err != nil {
gerr = err
@ -270,10 +269,20 @@ func (m *mdnsRegistry) GetService(service string) ([]*Service, error) {
Endpoints: txt.Endpoints,
}
}
addr := ""
// prefer ipv4 addrs
if e.AddrV4 != nil {
addr = e.AddrV4.String()
// else use ipv6
} else if e.AddrV6 != nil {
addr = "[" + e.AddrV6.String() + "]"
} else {
// broken endpoint
continue
}
s.Nodes = append(s.Nodes, &Node{
Id: strings.TrimSuffix(e.Name, "."+p.Service+"."+p.Domain+"."),
Address: fmt.Sprintf("%s:%d", e.AddrV4.String(), e.Port),
Address: fmt.Sprintf("%s:%d", addr, e.Port),
Metadata: txt.Metadata,
})