package openWeatherMap import ( "ArinDash/config" "encoding/json" "io" "log" "net/http" ) const apiBaseURL = "https://api.openweathermap.org/data/2.5/weather" type configFile struct { OpenWeatherMap openWeatherMapConfig } type openWeatherMapConfig struct { LocationId string ApiKey string } func FetchCurrentWeather() CurrentWeather { cfg := &configFile{} config.LoadConfig(cfg) client := &http.Client{} currentWeather := &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) } resp, err := client.Do(req) if err != nil { log.Fatal(err) } defer resp.Body.Close() respBody, err := io.ReadAll(resp.Body) if err != nil { log.Fatal(err) } err = json.Unmarshal(respBody, currentWeather) return *currentWeather }