registry/mdns: fix ipv6 addr in mdns registry
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
077063c212
commit
55c19afb0b
@ -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,
|
||||
})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user