Documentation
¶
Overview ¶
Package openweather contains helper functions to query OpenWeatherMaps (http://openweathermap.org/) for weather information. Currently the current weather API (http://openweathermap.org/current) and the 5 days forecast API (http://openweathermap.org/forecast5) are supported.
Index ¶
- func DailyForecast5URL(q Query) string
- func DailyForecast16URL(q Query) string
- func WeatherIconURL(iconID string) (url string)
- func WeatherURL(q Query) string
- type CurrentWeather
- type DailyForecast5
- type DailyForecast16
- type Query
- func (query Query) DailyForecast5() (*DailyForecast5, error)
- func (query Query) DailyForecast5Raw() (json string, err error)
- func (query Query) DailyForecast16() (*DailyForecast16, error)
- func (query Query) DailyForecast16Raw() (json string, err error)
- func (query Query) Weather() (*CurrentWeather, error)
- func (query Query) WeatherRaw() (json string, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DailyForecast5URL ¶
DailyForecast5URL returns a matching url for the given query which can be used to obtain the 5 days forecast from openweathermap.org.
func DailyForecast16URL ¶
DailyForecast16URL returns a matching url for the given query which can be used to obtain the 16 days forecast from openweathermap.org.
func WeatherIconURL ¶
WeatherIconURL returns an url to download matching icon for given weather id.
func WeatherURL ¶
WeatherURL returns a matching url for the given query which can be used to obtain the current weather information from openweathermap.org.
Types ¶
type CurrentWeather ¶
type CurrentWeather struct {
Coord struct {
Lon float64 `json:"lon"`
Lat float64 `json:"lat"`
} `json:"coord"`
Weather []struct {
ID int `json:"id"`
Main string `json:"main"`
Description string `json:"description"`
Icon string `json:"icon"`
} `json:"weather"`
Base string `json:"base"`
Main struct {
Temp float64 `json:"temp"`
Pressure int `json:"pressure"`
Humidity int `json:"humidity"`
TempMin float64 `json:"temp_min"`
TempMax float64 `json:"temp_max"`
} `json:"main"`
Wind struct {
Speed float64 `json:"speed"`
Deg int `json:"deg"`
} `json:"wind"`
Clouds struct {
All int `json:"all"`
} `json:"clouds"`
Rain struct {
ThreeH int `json:"3h"`
} `json:"rain"`
Dt int `json:"dt"`
Sys struct {
Type int `json:"type"`
ID int `json:"id"`
Message float64 `json:"message"`
Country string `json:"country"`
Sunrise int `json:"sunrise"`
Sunset int `json:"sunset"`
} `json:"sys"`
ID int `json:"id"`
Name string `json:"name"`
Cod int `json:"cod"`
}
CurrentWeather represents unmarshalled data from openweathermap for the current weather API (http://openweathermap.org/current).
type DailyForecast5 ¶
type DailyForecast5 struct {
Cod string `json:"cod"`
Message float64 `json:"message"`
City struct {
GeonameID int `json:"geoname_id"`
Name string `json:"name"`
Lat float64 `json:"lat"`
Lon float64 `json:"lon"`
Country string `json:"country"`
Iso2 string `json:"iso2"`
Type string `json:"type"`
Population int `json:"population"`
} `json:"city"`
Cnt int `json:"cnt"`
List []struct {
Dt int `json:"dt"`
Temp struct {
Day float64 `json:"day"`
Min float64 `json:"min"`
Max float64 `json:"max"`
Night float64 `json:"night"`
Eve float64 `json:"eve"`
Morn float64 `json:"morn"`
} `json:"temp"`
Pressure float64 `json:"pressure"`
Humidity int `json:"humidity"`
Weather []struct {
ID int `json:"id"`
Main string `json:"main"`
Description string `json:"description"`
Icon string `json:"icon"`
} `json:"weather"`
Speed float64 `json:"speed"`
Deg int `json:"deg"`
Clouds int `json:"clouds"`
Snow float64 `json:"snow,omitempty"`
} `json:"list"`
}
DailyForecast5 represents unmarshalled data from openweathermap for the 5 days forecast weather API (http://openweathermap.org/forecast5).
type DailyForecast16 ¶
type DailyForecast16 struct {
Cod string `json:"cod"`
Message float64 `json:"message"`
City struct {
ID int `json:"id"`
Name string `json:"name"`
Coord struct {
Lon float64 `json:"lon"`
Lat float64 `json:"lat"`
} `json:"coord"`
Country string `json:"country"`
} `json:"city"`
Cnt int `json:"cnt"`
List []struct {
Dt int `json:"dt"`
Temp struct {
Day float64 `json:"day"`
Min float64 `json:"min"`
Max float64 `json:"max"`
Night float64 `json:"night"`
Eve float64 `json:"eve"`
Morn float64 `json:"morn"`
} `json:"temp"`
Pressure float64 `json:"pressure"`
Humidity int `json:"humidity"`
Weather []struct {
ID int `json:"id"`
Main string `json:"main"`
Description string `json:"description"`
Icon string `json:"icon"`
} `json:"weather"`
} `json:"list"`
}
DailyForecast16 represents unmarshalled data from openweathermap for the 16 days forecast weather API (http://openweathermap.org/forecast16).
type Query ¶
type Query struct {
APIKey string
Unit string
Query string
// contains filtered or unexported fields
}
Query represents a pending request to openweathermap.
func NewQueryForCity ¶
NewQueryForCity creates a query for openweathermap from city name. The unit is optional and defaults to metric.
func NewQueryForID ¶
NewQueryForID creates a query for openweathermap from city id. The unit is optional and defaults to metric.
func NewQueryForLocation ¶
NewQueryForLocation creates a query for openweathermap from latitude and longitude. The unit is optional and defaults to metric.
func NewQueryForZip ¶
NewQueryForZip creates a query for openweathermap from zip code. The unit is optional and defaults to metric.
func (Query) DailyForecast5 ¶
func (query Query) DailyForecast5() (*DailyForecast5, error)
DailyForecast5 downloads 5 days forecast data from openweathermap and return them as DailyForecast5.
func (Query) DailyForecast5Raw ¶
DailyForecast5Raw downloads 5 days forecast data from openweathermap and return them as string.
func (Query) DailyForecast16 ¶
func (query Query) DailyForecast16() (*DailyForecast16, error)
DailyForecast16 downloads 16 days forecast data from openweathermap and return them as DailyForecast16. Warning: the 16 days forecast requires a paid account.
func (Query) DailyForecast16Raw ¶
DailyForecast16Raw downloads 16 days forecast data from openweathermap and return them as string. Warning: the 16 days forecast requires a paid account.
func (Query) Weather ¶
func (query Query) Weather() (*CurrentWeather, error)
Weather downloads current weather data from openweathermap and return them as WeatherData.
func (Query) WeatherRaw ¶
WeatherRaw downloads current weather data from openweathermap and return them as string.