getLocalIP returns a non loopback local IP of the host
()
| 80 | |
| 81 | // getLocalIP returns a non loopback local IP of the host |
| 82 | func getLocalIP() string { |
| 83 | addrs, err := net.InterfaceAddrs() |
| 84 | if err != nil { |
| 85 | return "" |
| 86 | } |
| 87 | |
| 88 | for _, address := range addrs { |
| 89 | // check the address type and if it is not a loopback then return it |
| 90 | if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() { |
| 91 | if ipnet.IP.To4() != nil { |
| 92 | return ipnet.IP.String() |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | return "" |
| 97 | } |
| 98 | |
| 99 | type topic struct { |
| 100 | Name string |
no test coverage detected
searching dependent graphs…