Fix some error logging - Msg() needs to be called for exiting with exit 1
This commit is contained in:
		@@ -30,7 +30,7 @@ The `-c` flag allows to give a country code. Else `ch` will be used.
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Background
 | 
					## 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.
 | 
					and outputs the server with the lowest ping.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Integration into a script
 | 
					## Integration into a script
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										6
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								main.go
									
									
									
									
									
								
							@@ -40,7 +40,7 @@ func main() {
 | 
				
			|||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		serverJson, err := json.Marshal(best)
 | 
							serverJson, err := json.Marshal(best)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			log.Fatal().Err(err)
 | 
								log.Fatal().Err(err).Msg("Couldn't marshal server information to Json")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		fmt.Println(string(serverJson))
 | 
							fmt.Println(string(serverJson))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -66,7 +66,7 @@ func selectBestServerIndex(servers []server, country string) int {
 | 
				
			|||||||
func getServers(serverType string) []server {
 | 
					func getServers(serverType string) []server {
 | 
				
			||||||
	resp, err := http.Get("https://api.mullvad.net/www/relays/" + serverType + "/")
 | 
						resp, err := http.Get("https://api.mullvad.net/www/relays/" + serverType + "/")
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		log.Fatal().Err(err)
 | 
							log.Fatal().Err(err).Msg("Couldn't retrieve servers")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	responseBody, err := ioutil.ReadAll(resp.Body)
 | 
						responseBody, err := ioutil.ReadAll(resp.Body)
 | 
				
			||||||
	defer func(Body io.ReadCloser) {
 | 
						defer func(Body io.ReadCloser) {
 | 
				
			||||||
@@ -81,7 +81,7 @@ func getServers(serverType string) []server {
 | 
				
			|||||||
	var servers []server
 | 
						var servers []server
 | 
				
			||||||
	err = json.Unmarshal(responseBody, &servers)
 | 
						err = json.Unmarshal(responseBody, &servers)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		log.Fatal().Err(err)
 | 
							log.Fatal().Err(err).Msg("couldn't unmarshall server json")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return servers
 | 
						return servers
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user