Cleaned up error handling

This commit is contained in:
Andrew Scott 2022-07-08 04:01:38 -04:00
parent 6b8e4a3b86
commit e201d20ebd
Signed by: a
GPG key ID: 3EB62D0BBB8DB381

View file

@ -2,7 +2,6 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
@ -12,11 +11,8 @@ import (
func getLocation(wg *sync.WaitGroup, cfg *config) {
errMsg := "\nSorry, couldn't get your location automatically"
res, err := http.Get("https://ipinfo.io/json")
if err != nil {
fmt.Println(errMsg)
log.Println(err)
return
}
@ -24,14 +20,12 @@ func getLocation(wg *sync.WaitGroup, cfg *config) {
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(errMsg)
log.Panicln(err)
log.Println(err)
}
err = json.Unmarshal(body, &cfg)
if err != nil {
fmt.Println(errMsg)
log.Fatalln(err)
log.Println(err)
}
loc := strings.Split(cfg.Location, ",")