From c6d352c83291db0a11baa327ed1a36e06f806060 Mon Sep 17 00:00:00 2001 From: Chris Moran Date: Wed, 16 Mar 2022 22:22:05 -0400 Subject: [PATCH] #2453 Fix with associated test update (#2454) --- registry/mdns_registry.go | 12 ++++++------ registry/mdns_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/registry/mdns_registry.go b/registry/mdns_registry.go index aed224ab..a34689b0 100644 --- a/registry/mdns_registry.go +++ b/registry/mdns_registry.go @@ -354,10 +354,10 @@ func (m *mdnsRegistry) GetService(service string, opts ...GetOption) ([]*Service addr := "" // prefer ipv4 addrs if len(e.AddrV4) > 0 { - addr = e.AddrV4.String() + addr = net.JoinHostPort(e.AddrV4.String(), fmt.Sprint(e.Port)) // else use ipv6 } else if len(e.AddrV6) > 0 { - addr = "[" + e.AddrV6.String() + "]" + addr = net.JoinHostPort(e.AddrV6.String(), fmt.Sprint(e.Port)) } else { if logger.V(logger.InfoLevel, logger.DefaultLogger) { logger.Infof("[mdns]: invalid endpoint received: %v", e) @@ -366,7 +366,7 @@ func (m *mdnsRegistry) GetService(service string, opts ...GetOption) ([]*Service } s.Nodes = append(s.Nodes, &Node{ Id: strings.TrimSuffix(e.Name, "."+p.Service+"."+p.Domain+"."), - Address: net.JoinHostPort(addr, fmt.Sprint(e.Port)), + Address: addr, Metadata: txt.Metadata, }) @@ -584,16 +584,16 @@ func (m *mdnsWatcher) Next() (*Result, error) { var addr string if len(e.AddrV4) > 0 { - addr = e.AddrV4.String() + addr = net.JoinHostPort(e.AddrV4.String(), fmt.Sprint(e.Port)) } else if len(e.AddrV6) > 0 { - addr = "[" + e.AddrV6.String() + "]" + addr = net.JoinHostPort(e.AddrV6.String(), fmt.Sprint(e.Port)) } else { addr = e.Addr.String() } service.Nodes = append(service.Nodes, &Node{ Id: strings.TrimSuffix(e.Name, suffix), - Address: net.JoinHostPort(addr, fmt.Sprint(e.Port)), + Address: addr, Metadata: txt.Metadata, }) diff --git a/registry/mdns_test.go b/registry/mdns_test.go index 5f5cc617..a7b17fc4 100644 --- a/registry/mdns_test.go +++ b/registry/mdns_test.go @@ -52,6 +52,19 @@ func TestMDNS(t *testing.T) { }, }, }, + { + Name: "test4", + Version: "1.0.4", + Nodes: []*Node{ + { + Id: "test4-1", + Address: "[::]:10004", + Metadata: map[string]string{ + "foo4": "bar4", + }, + }, + }, + }, } travis := os.Getenv("TRAVIS") @@ -243,6 +256,19 @@ func TestWatcher(t *testing.T) { }, }, }, + { + Name: "test4", + Version: "1.0.4", + Nodes: []*Node{ + { + Id: "test4-1", + Address: "[::]:10004", + Metadata: map[string]string{ + "foo4": "bar4", + }, + }, + }, + }, } testFn := func(service, s *Service) {