mirror of
https://codeberg.org/andyscott/weather-cli.git
synced 2024-11-09 06:00:52 -05:00
34 lines
627 B
Go
34 lines
627 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io/ioutil"
|
|
"log"
|
|
"net/http"
|
|
)
|
|
|
|
func getCurrent(app *application) {
|
|
|
|
lat := "lat=" + app.Config.Latitude
|
|
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
|
|
|
|
res, err := http.Get(url)
|
|
if err != nil {
|
|
log.Println(err)
|
|
}
|
|
defer res.Body.Close()
|
|
|
|
body, err := ioutil.ReadAll(res.Body)
|
|
if err != nil {
|
|
log.Println(err)
|
|
}
|
|
|
|
err = json.Unmarshal(body, &app.Forecast)
|
|
if err != nil {
|
|
log.Println(err)
|
|
}
|
|
app.WaitGroup.Done()
|
|
}
|