mirror of
https://codeberg.org/andyscott/weather-cli.git
synced 2024-11-08 05:50:51 -05:00
Error handling, api update
This commit is contained in:
parent
a688c5a1d9
commit
27f7717c8a
3 changed files with 9 additions and 9 deletions
|
@ -24,12 +24,12 @@ func getLocation(app *Application) {
|
|||
|
||||
body, err := ioutil.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
log.Printf("Error reading location from server: %v\n", err)
|
||||
}
|
||||
|
||||
err = json.Unmarshal(body, &app.Config)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
log.Printf("Error reading JSON from server: %v", err)
|
||||
}
|
||||
|
||||
loc := strings.Split(app.Config.Location, ",")
|
||||
|
|
|
@ -50,12 +50,12 @@ type Date struct {
|
|||
}
|
||||
|
||||
type Config struct {
|
||||
Units string `json:"units"`
|
||||
Units string
|
||||
Location string `json:"loc"`
|
||||
Longitude string `json:"lat"`
|
||||
Latitude string `json:"lon"`
|
||||
Date Date
|
||||
ApiKey string `json:"appid"`
|
||||
ApiKey string
|
||||
}
|
||||
|
||||
type Application struct {
|
||||
|
|
|
@ -15,22 +15,22 @@ func getCurrent(app *Application) {
|
|||
lon := "&lon=" + app.Config.Longitude
|
||||
units := "&units=" + app.Config.Units
|
||||
key := "&appid=" + app.Config.ApiKey
|
||||
url := "https://pro.openweathermap.org/data/2.5/weather?" + lat + lon + units + key
|
||||
url := "https://api.openweathermap.org/data/2.5/weather?" + lat + lon + units + key
|
||||
|
||||
res, err := http.Get(url)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
log.Printf("Error getting current forecast: %v", err)
|
||||
}
|
||||
defer res.Body.Close()
|
||||
fmt.Println(res.Body)
|
||||
body, err := ioutil.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
log.Printf("Error reading response from server: %v\n", err)
|
||||
}
|
||||
|
||||
err = json.Unmarshal(body, &app.Forecast)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
log.Printf("Error reading JSON from server: %v\n", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ func getCurrentByLoc(app *Application) {
|
|||
zip := app.Config.Location
|
||||
units := "&units=" + app.Config.Units
|
||||
key := "&appid=" + app.Config.ApiKey
|
||||
url := "https://pro.openweathermap.org/data/2.5/weather?q=" + zip + units + key
|
||||
url := "https://api.openweathermap.org/data/2.5/weather?q=" + zip + units + key
|
||||
|
||||
res, err := http.Get(url)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue