Merge pull request #18 from botto/fail-on-no-internet

Fail on no internet
This commit is contained in:
Callan Bryant 2020-09-08 08:12:18 +01:00 committed by GitHub
commit a4b900dee7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -56,7 +56,8 @@ func getRandomNetwork() JSONIPNet {
// TODO support IPv6
func getExternalIP() net.IP {
conn, _ := net.Dial("udp", "8.8.8.8:80")
conn, err := net.Dial("udp", "8.8.8.8:80")
check(err, "Could not detect internet connection")
defer conn.Close()
localAddr := conn.LocalAddr().String()

View File

@ -7,8 +7,11 @@ import (
"strings"
)
func check(e error) {
func check(e error, optMsg ...string) {
if e != nil {
if (len(optMsg) > 0) {
ExitFail("%s - %s", e, strings.Join(optMsg, " "))
}
ExitFail("%s", e)
}
}