Fix some error logging - Msg() needs to be called for exiting with exit 1

This commit is contained in:
Bastian Doetsch 2022-03-19 17:00:48 +01:00
parent 415cfa8ee7
commit 2b05df2b75
2 changed files with 4 additions and 4 deletions

View File

@ -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/<SERVER_TYPE/` to get the current server list, pings the ones with the right country
The program uses `https://api.mullvad.net/www/relays/<SERVER_TYPE>/` 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

View File

@ -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
}