GetLocalIPs returns IP addresses associated with the machine
()
| 108 | |
| 109 | // GetLocalIPs returns IP addresses associated with the machine |
| 110 | func GetLocalIPs() ([]string, error) { |
| 111 | addrs, err := net.InterfaceAddrs() |
| 112 | if err != nil { |
| 113 | return nil, err |
| 114 | } |
| 115 | |
| 116 | var localIPs []string |
| 117 | for _, addr := range addrs { |
| 118 | switch v := addr.(type) { |
| 119 | case *net.IPNet: |
| 120 | if v.IP.IsLoopback() || v.IP.To4() == nil { |
| 121 | continue |
| 122 | } |
| 123 | localIPs = append(localIPs, v.IP.String()) |
| 124 | case *net.IPAddr: |
| 125 | if v.IP.IsLoopback() || v.IP.To4() == nil { |
| 126 | continue |
| 127 | } |
| 128 | localIPs = append(localIPs, v.IP.String()) |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | return localIPs, nil |
| 133 | } |
| 134 | |
| 135 | // BaseURLFromFullURL returns the base url (http://hostname.example.com) from a URL, without port |
| 136 | func BaseURLFromFullURL(fullURL string) string { |
no outgoing calls
no test coverage detected