From cca8826a1fa8b02cff2911271991c2eeda1853eb Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Mon, 15 Jun 2020 16:13:45 +0100 Subject: [PATCH] registry/mdns: fix nil host bug (#1703) --- registry/mdns_registry.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/registry/mdns_registry.go b/registry/mdns_registry.go index 8ecd37ec..9496fe0a 100644 --- a/registry/mdns_registry.go +++ b/registry/mdns_registry.go @@ -563,9 +563,7 @@ func (m *mdnsWatcher) Next() (*Result, error) { if len(m.wo.Service) > 0 && txt.Service != m.wo.Service { continue } - var action string - if e.TTL == 0 { action = "delete" } else { @@ -584,9 +582,18 @@ func (m *mdnsWatcher) Next() (*Result, error) { continue } + var addr string + if len(e.AddrV4) > 0 { + addr = e.AddrV4.String() + } else if len(e.AddrV6) > 0 { + addr = "[" + e.AddrV6.String() + "]" + } else { + addr = e.Addr.String() + } + service.Nodes = append(service.Nodes, &Node{ Id: strings.TrimSuffix(e.Name, suffix), - Address: fmt.Sprintf("%s:%d", e.AddrV4.String(), e.Port), + Address: fmt.Sprintf("%s:%d", addr, e.Port), Metadata: txt.Metadata, })