From 2b05df2b75c4645095dd2843d29b5a9d9dee6989 Mon Sep 17 00:00:00 2001 From: Bastian Doetsch Date: Sat, 19 Mar 2022 17:00:48 +0100 Subject: [PATCH] Fix some error logging - Msg() needs to be called for exiting with exit 1 --- README.md | 2 +- main.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f03aaae..1016726 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ The `-c` flag allows to give a country code. Else `ch` will be used. ## Background -The program uses `https://api.mullvad.net/www/relays//` to get the current server list, pings the ones with the right country and outputs the server with the lowest ping. ## Integration into a script diff --git a/main.go b/main.go index 2e94a15..d6bdb41 100644 --- a/main.go +++ b/main.go @@ -40,7 +40,7 @@ func main() { } else { serverJson, err := json.Marshal(best) if err != nil { - log.Fatal().Err(err) + log.Fatal().Err(err).Msg("Couldn't marshal server information to Json") } fmt.Println(string(serverJson)) } @@ -66,7 +66,7 @@ func selectBestServerIndex(servers []server, country string) int { func getServers(serverType string) []server { resp, err := http.Get("https://api.mullvad.net/www/relays/" + serverType + "/") if err != nil { - log.Fatal().Err(err) + log.Fatal().Err(err).Msg("Couldn't retrieve servers") } responseBody, err := ioutil.ReadAll(resp.Body) defer func(Body io.ReadCloser) { @@ -81,7 +81,7 @@ func getServers(serverType string) []server { var servers []server err = json.Unmarshal(responseBody, &servers) if err != nil { - log.Fatal().Err(err) + log.Fatal().Err(err).Msg("couldn't unmarshall server json") } return servers }