mirror of
https://codeberg.org/andyscott/weather-cli.git
synced 2024-11-09 06:00:52 -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 (
|
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, ",")
|
||||||
|
|
Loading…
Reference in a new issue