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