1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-11-24 08:02:32 +02:00

Merge pull request #1660 from micro/bugfix/mdns_nil_host

Check ipv4 or ipv6 address is valid before assigning
This commit is contained in:
Dominic Wong 2020-05-27 15:53:27 +01:00 committed by GitHub
commit 1da8a640da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -353,10 +353,10 @@ func (m *mdnsRegistry) GetService(service string, opts ...GetOption) ([]*Service
}
addr := ""
// prefer ipv4 addrs
if e.AddrV4 != nil {
if len(e.AddrV4) > 0 {
addr = e.AddrV4.String()
// else use ipv6
} else if e.AddrV6 != nil {
} else if len(e.AddrV6) > 0 {
addr = "[" + e.AddrV6.String() + "]"
} else {
if logger.V(logger.InfoLevel, logger.DefaultLogger) {

View File

@ -34,7 +34,7 @@ type ServiceEntry struct {
// complete is used to check if we have all the info we need
func (s *ServiceEntry) complete() bool {
return (s.AddrV4 != nil || s.AddrV6 != nil || s.Addr != nil) && s.Port != 0 && s.hasTXT
return (len(s.AddrV4) > 0 || len(s.AddrV6) > 0 || len(s.Addr) > 0) && s.Port != 0 && s.hasTXT
}
// QueryParam is used to customize how a Lookup is performed