mirror of
https://codeberg.org/andyscott/weather-cli.git
synced 2024-12-21 12:43:09 -05:00
Cleaned up error handling
This commit is contained in:
parent
6b8e4a3b86
commit
e201d20ebd
1 changed files with 2 additions and 8 deletions
|
@ -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, ",")
|
||||
|
|
Loading…
Reference in a new issue