39
)
40
42
>
// lookup localhost and favor the first ipv4 address
43
>
// unless there are only ipv6 addresses available
44
>
ips, err := net.LookupIP(domain)
45
>
if err != nil || len(ips) == 0 {
46
// fallback to default instead of error
47
return localhostIPDefault
48
}
50
>
if ip4 := ip.To4(); ip4 != nil {
52
>
}
53
}
54
return ips[len(ips)-1].String()