1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-18 08:26:38 +02:00

#2453 Fix with associated test update (#2454)

This commit is contained in:
Chris Moran 2022-03-16 22:22:05 -04:00 committed by GitHub
parent 356448017f
commit c6d352c832
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 6 deletions

View File

@ -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,
})

View File

@ -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) {