Localhost returns the first address found when doing a lookup of "localhost". If not successful, it looks for an ip on the loopback interfaces.
()
| 101 | // doing a lookup of "localhost". If not successful, |
| 102 | // it looks for an ip on the loopback interfaces. |
| 103 | func Localhost() (net.IP, error) { |
| 104 | if ip := localhostLookup(); ip != nil { |
| 105 | return ip, nil |
| 106 | } |
| 107 | if ip := loopbackIP(); ip != nil { |
| 108 | return ip, nil |
| 109 | } |
| 110 | return nil, errors.New("no loopback ip found") |
| 111 | } |
| 112 | |
| 113 | // localhostLookup looks for a loopback IP by resolving localhost. |
| 114 | func localhostLookup() net.IP { |