Add News widget and integrate NewsAPI for live updates
This commit is contained in:
@@ -3,21 +3,22 @@ package openWeatherMap
|
||||
import "time"
|
||||
|
||||
type CurrentWeather struct {
|
||||
Base string `json:"base"`
|
||||
Visibility int `json:"visibility"`
|
||||
Dt int `json:"dt"`
|
||||
Timezone int `json:"timezone"`
|
||||
Id int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Cod int `json:"cod"`
|
||||
Coordinates Coordinates `json:"coord"`
|
||||
Weather []Weather `json:"weather"`
|
||||
Wind Wind `json:"wind"`
|
||||
Clouds Clouds `json:"clouds"`
|
||||
Rain Rain `json:"rain"`
|
||||
Snow Snow `json:"snow"`
|
||||
Sys Sys `json:"sys"`
|
||||
Main Main `json:"main"`
|
||||
Base string `json:"base"`
|
||||
Visibility int `json:"visibility"`
|
||||
Dt int `json:"dt"`
|
||||
Timezone int `json:"timezone"`
|
||||
Id int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Cod int `json:"cod"`
|
||||
Coordinates Coordinates `json:"coord"`
|
||||
Weather []Weather `json:"weather"`
|
||||
Wind Wind `json:"wind"`
|
||||
Clouds Clouds `json:"clouds"`
|
||||
Rain Rain `json:"rain"`
|
||||
Snow Snow `json:"snow"`
|
||||
Sys Sys `json:"sys"`
|
||||
Main Main `json:"main"`
|
||||
ErrorMessage string
|
||||
}
|
||||
|
||||
type Coordinates struct {
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"ArinDash/config"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
@@ -27,16 +26,22 @@ func FetchCurrentWeather() CurrentWeather {
|
||||
|
||||
req, err := http.NewRequest("GET", apiBaseURL+"?id="+cfg.OpenWeatherMap.LocationId+"&units=metric&lang=en&APPID="+cfg.OpenWeatherMap.ApiKey, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return CurrentWeather{
|
||||
ErrorMessage: err.Error(),
|
||||
}
|
||||
}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return CurrentWeather{
|
||||
ErrorMessage: err.Error(),
|
||||
}
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
respBody, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return CurrentWeather{
|
||||
ErrorMessage: err.Error(),
|
||||
}
|
||||
}
|
||||
|
||||
err = json.Unmarshal(respBody, currentWeather)
|
||||
|
||||
Reference in New Issue
Block a user