Documentation ¶
Overview ¶
Package openweathermap is a library for use to access the http://openweathermap.org API. JSON is the only return format supported at this time.
Index ¶
- Variables
- func ConvertToURLValues(data map[string]string) string
- func Init() error
- func RetrieveIcon(destination, iconFile string) (int64, error)
- func SendStationData(data url.Values)
- func ValidDataUnit(u string) bool
- func ValidDataUnitSymbol(u string) bool
- func ValidLangCode(c string) bool
- func ValidateApiKey(aApiKey string) bool
- func ValidateStationDataParameter(param string) bool
- type APIError
- type City
- type Clouds
- type ConditionData
- type ConfigData
- func (c *ConfigData) CheckAPIKeyExists() bool
- func (me *ConfigData) GetApiKey() string
- func (me *ConfigData) GetPassword() string
- func (me *ConfigData) GetUsername() string
- func (me *ConfigData) SetApiKey(aNewApiKey string)
- func (me *ConfigData) SetAuthenticationCredentials(aUsername, aPassword string)
- type Coordinates
- type CurrentWeatherData
- func (w *CurrentWeatherData) CurrentByArea()
- func (w *CurrentWeatherData) CurrentByCoordinates(location *Coordinates) error
- func (w *CurrentWeatherData) CurrentByID(id int) error
- func (w *CurrentWeatherData) CurrentByName(location string) error
- func (w *CurrentWeatherData) CurrentByZip(zip int, countryCode string) error
- func (w *CurrentWeatherData) SetLang(lang string) error
- type Forecast3HData
- type Forecast3HList
- type ForecastSys
- type ForecastWeatherData
- type ForecastWeatherList
- type HistoricalParameters
- type HistoricalWeatherData
- type IconData
- type Main
- type Rain
- type Snow
- type Sys
- type Temperature
- type Weather
- type WeatherHistory
- type Wind
Constants ¶
This section is empty.
Variables ¶
var AdditionalConditions = []*ConditionData{
{ID: 951, Meaning: "calm", Icon1: ""},
{ID: 952, Meaning: "light breeze", Icon1: ""},
{ID: 953, Meaning: "gentle breeze", Icon1: ""},
{ID: 954, Meaning: "moderate breeze", Icon1: ""},
{ID: 955, Meaning: "fresh breeze", Icon1: ""},
{ID: 956, Meaning: "strong breeze", Icon1: ""},
{ID: 957, Meaning: "high wind, near gale", Icon1: ""},
{ID: 958, Meaning: "gale", Icon1: ""},
{ID: 959, Meaning: "severe gale", Icon1: ""},
{ID: 960, Meaning: "storm", Icon1: ""},
{ID: 961, Meaning: "violent storm", Icon1: ""},
{ID: 962, Meaning: "hurricane", Icon1: ""},
}
AdditionalConditions is a slive of ConditionData pointers
var AtmosphereConditions = []*ConditionData{
{ID: 701, Meaning: "mist", Icon1: "50d.png"},
{ID: 711, Meaning: "smoke", Icon1: "50d.png"},
{ID: 721, Meaning: "haze", Icon1: "50d.png"},
{ID: 731, Meaning: "sand, dust whirls", Icon1: "50d.png"},
{ID: 741, Meaning: "fog", Icon1: "50d.png"},
{ID: 751, Meaning: "sand", Icon1: "50d.png"},
{ID: 761, Meaning: "dust", Icon1: "50d.png"},
{ID: 762, Meaning: "volcanic ash", Icon1: "50d.png"},
{ID: 771, Meaning: "squalls", Icon1: "50d.png"},
{ID: 781, Meaning: "tornado", Icon1: "50d.png"},
}
AtmosphereConditions is a slice of ConditionData pointers
var CloudConditions = []*ConditionData{
{ID: 800, Meaning: "clear sky", Icon1: "01d.png", Icon2: "01n.png"},
{ID: 801, Meaning: "few clouds", Icon1: "02d.png", Icon2: " 02n.png"},
{ID: 802, Meaning: "scattered clouds", Icon1: "03d.png", Icon2: "03d.png"},
{ID: 803, Meaning: "broken clouds", Icon1: "04d.png", Icon2: "03d.png"},
{ID: 804, Meaning: "overcast clouds", Icon1: "04d.png", Icon2: "04d.png"},
}
CloudConditions is a slice of ConditionData pointers
var Config = ConfigData{}
config will hold default settings to be passed into the OWM requests
var DataUnits = map[string]string{"C": "metric", "F": "imperial", "K": "internal"}
DataUnits represents the character chosen to represent the temperature notation
var DrizzleConditions = []*ConditionData{
{ID: 300, Meaning: "light intensity drizzle", Icon1: "09d.png"},
{ID: 301, Meaning: "drizzle", Icon1: "09d.png"},
{ID: 302, Meaning: "heavy intensity drizzle", Icon1: "09d.png"},
{ID: 310, Meaning: "light intensity drizzle rain", Icon1: "09d.png"},
{ID: 311, Meaning: "drizzle rain", Icon1: "09d.png"},
{ID: 312, Meaning: "heavy intensity drizzle rain", Icon1: "09d.png"},
{ID: 313, Meaning: "shower rain and drizzle", Icon1: "09d.png"},
{ID: 314, Meaning: "heavy shower rain and drizzle", Icon1: "09d.png"},
{ID: 321, Meaning: "shower drizzle", Icon1: "09d.png"},
}
DrizzleConditions is a slice of ConditionData pointers
var ErrApiKeyNotFound = errors.New("OWM Api key not found!")
var ErrNoApiKeyInEnvVar = errors.New("OWM API key not found in environment variables!")
var ExtremeConditions = []*ConditionData{
{ID: 900, Meaning: "tornado", Icon1: ""},
{ID: 901, Meaning: "tropical storm", Icon1: ""},
{ID: 902, Meaning: "hurricane", Icon1: ""},
{ID: 903, Meaning: "cold", Icon1: ""},
{ID: 904, Meaning: "hot", Icon1: ""},
{ID: 905, Meaning: "windy", Icon1: ""},
{ID: 906, Meaning: "hail", Icon1: ""},
}
ExtremeConditions is a slice of ConditionData pointers
var IconList = []*IconData{
{Condition: "clear sky", Day: "01d.png", Night: "01n.png"},
{Condition: "few clouds", Day: "02d.png", Night: "02n.png"},
{Condition: "scattered clouds", Day: "03d.png", Night: "03n.png"},
{Condition: "broken clouds", Day: "04d.png", Night: "04n.png"},
{Condition: "shower rain", Day: "09d.png", Night: "09n.png"},
{Condition: "rain", Day: "10d.png", Night: "10n.png"},
{Condition: "thunderstorm", Day: "11d.png", Night: "11n.png"},
{Condition: "snow", Day: "13d.png", Night: "13n.png"},
{Condition: "mist", Day: "50d.png", Night: "50n.png"},
}
IconList is a slice of IconData pointers
var LangCodes = map[string]string{
"EN": "English",
"RU": "Russian",
"IT": "Italian",
"ES": "Spanish",
"SP": "Spanish",
"UK": "Ukrainian",
"UA": "Ukrainian",
"DE": "German",
"PT": "Portuguese",
"RO": "Romanian",
"PL": "Polish",
"FI": "Finnish",
"NL": "Dutch",
"FR": "French",
"BG": "Bulgarian",
"SV": "Swedish",
"SE": "Swedish",
"TR": "Turkish",
"HR": "Croatian",
"CA": "Catalan",
"ZH_TW": "Chinese Traditional",
"ZH": "Chinese Simplified",
"ZH_CN": "Chinese Simplified",
}
LangCodes holds all supported languages to be used inspried and sourced from @bambocher (github.com/bambocher)
var RainConditions = []*ConditionData{
{ID: 500, Meaning: "light rain", Icon1: "09d.png"},
{ID: 501, Meaning: "moderate rain", Icon1: "09d.png"},
{ID: 502, Meaning: "heavy intensity rain", Icon1: "09d.png"},
{ID: 503, Meaning: "very heavy rain", Icon1: "09d.png"},
{ID: 504, Meaning: "extreme rain", Icon1: "09d.png"},
{ID: 511, Meaning: "freezing rain", Icon1: "13d.png"},
{ID: 520, Meaning: "light intensity shower rain", Icon1: "09d.png"},
{ID: 521, Meaning: "shower rain", Icon1: "09d.png"},
{ID: 522, Meaning: "heavy intensity shower rain", Icon1: "09d.png"},
{ID: 531, Meaning: "ragged shower rain", Icon1: "09d.png"},
}
RainConditions is a slice of ConditionData pointers
var SnowConditions = []*ConditionData{
{ID: 600, Meaning: "light snow", Icon1: "13d.png"},
{ID: 601, Meaning: "snow", Icon1: "13d.png"},
{ID: 602, Meaning: "heavy snow", Icon1: "13d.png"},
{ID: 611, Meaning: "sleet", Icon1: "13d.png"},
{ID: 612, Meaning: "shower sleet", Icon1: "13d.png"},
{ID: 615, Meaning: "light rain and snow", Icon1: "13d.png"},
{ID: 616, Meaning: "rain and snow", Icon1: "13d.png"},
{ID: 620, Meaning: "light shower snow", Icon1: "13d.png"},
{ID: 621, Meaning: "shower snow", Icon1: "13d.png"},
{ID: 622, Meaning: "heavy shower snow", Icon1: "13d.png"},
}
SnowConditions is a slice of ConditionData pointers
var StationDataParameters = []string{
"wind_dir",
"wind_speed",
"wind_gust",
"temp",
"humidity",
"pressure",
"rain_1h",
"rain_24h",
"rain_today",
"snow",
"lum",
"lat",
"long",
"alt",
"radiation",
"dewpoint",
"uv",
"name",
}
Slice of type string of the valid parameters to be sent from a station. The API refers to this data as the "Weather station data transmission protocol"
var ThunderstormConditions = []*ConditionData{
{ID: 200, Meaning: "thunderstorm with light rain", Icon1: "11d.png"},
{ID: 201, Meaning: "thunderstorm with rain", Icon1: "11d.png"},
{ID: 202, Meaning: "thunderstorm with heavy rain", Icon1: "11d.png"},
{ID: 210, Meaning: "light thunderstorm", Icon1: "11d.png"},
{ID: 211, Meaning: "thunderstorm", Icon1: "11d.png"},
{ID: 212, Meaning: "heavy thunderstorm", Icon1: "11d.png"},
{ID: 221, Meaning: "ragged thunderstorm", Icon1: "11d.png"},
{ID: 230, Meaning: "thunderstorm with light drizzle", Icon1: "11d.png"},
{ID: 231, Meaning: "thunderstorm with drizzle", Icon1: "11d.png"},
{ID: 232, Meaning: "thunderstorm with heavy drizzle", Icon1: "11d.png"},
}
ThunderstormConditions is a slice of ConditionData pointers
Functions ¶
func ConvertToURLValues ¶
ConvertToURLValues will convert a map to a url.Values instance. We're taking a map[string]string instead of something more type specific since the url.Values instance only takes strings to create the URL values.
func RetrieveIcon ¶
RetrieveIcon will get the specified icon from the API.
func SendStationData ¶
SendStationData will send an instance the provided url.Values to the provided URL.
func ValidDataUnit ¶
ValidDataUnit makes sure the string passed in is an accepted unit of measure to be used for the return data.
func ValidDataUnitSymbol ¶
ValidDataUnitSymbol makes sure the string passed in is an acceptable data unit symbol.
func ValidLangCode ¶
ValidLangCode makes sure the string passed in is an acceptable lang code.
func ValidateApiKey ¶
func ValidateStationDataParameter ¶
ValidateStationDataParameter will make sure that whatever parameter supplied is one that can actually be used in the POST request.
Types ¶
type City ¶
type City struct { ID int `json:"id"` Name string `json:"name"` Coord Coordinates `json:"coord"` Country string `json:"country"` Population int `json:"population"` Sys ForecastSys `json:"sys"` }
City data for given location
type Clouds ¶
type Clouds struct {
All int `json:"all"`
}
Clouds struct holds data regarding cloud cover.
type ConditionData ¶
ConditionData holds data structure for weather conditions information.
type ConfigData ¶
type ConfigData struct { Mode string // user choice of JSON or XML Unit string // measurement for results to be displayed. F, C, or K Lang string // should reference a key in the LangCodes map APIKey string // API Key for connecting to the OWM Username string // Username for posting data Password string // Pasword for posting data }
Config will hold default settings to be passed into the "NewCurrent, NewForecast, etc}" functions.
func (*ConfigData) CheckAPIKeyExists ¶
func (c *ConfigData) CheckAPIKeyExists() bool
CheckAPIKeyExists will see if an API key has been set.
func (*ConfigData) GetApiKey ¶
func (me *ConfigData) GetApiKey() string
GetApiKey returns the API key. This value can be set using SetApiKey function
func (*ConfigData) GetPassword ¶
func (me *ConfigData) GetPassword() string
func (*ConfigData) GetUsername ¶
func (me *ConfigData) GetUsername() string
func (*ConfigData) SetApiKey ¶
func (me *ConfigData) SetApiKey(aNewApiKey string)
SetApiKey sets the API key
func (*ConfigData) SetAuthenticationCredentials ¶
func (me *ConfigData) SetAuthenticationCredentials(aUsername, aPassword string)
SetAuthenticationCredentials sets username and password
type Coordinates ¶
Coordinates struct holds longitude and latitude data in returned JSON or as parameter data for requests using longitude and latitude.
type CurrentWeatherData ¶
type CurrentWeatherData struct { GeoPos Coordinates `json:"coord"` Sys Sys `json:"sys"` Base string `json:"base"` Weather []Weather `json:"weather"` Main Main `json:"main"` Wind Wind `json:"wind"` Clouds Clouds `json:"clouds"` Dt int `json:"dt"` ID int `json:"id"` Name string `json:"name"` Cod int `json:"cod"` Unit string Lang string }
CurrentWeatherData struct contains an aggregate view of the structs defined above for JSON to be unmarshaled into.
func NewCurrent ¶
func NewCurrent(unit, lang string) (*CurrentWeatherData, error)
NewCurrent returns a new CurrentWeatherData pointer with the supplied parameters
func (*CurrentWeatherData) CurrentByArea ¶
func (w *CurrentWeatherData) CurrentByArea()
CurrentByArea will provide the current weather for the provided area.
func (*CurrentWeatherData) CurrentByCoordinates ¶
func (w *CurrentWeatherData) CurrentByCoordinates(location *Coordinates) error
CurrentByCoordinates will provide the current weather with the provided location coordinates.
func (*CurrentWeatherData) CurrentByID ¶
func (w *CurrentWeatherData) CurrentByID(id int) error
CurrentByID will provide the current weather with the provided location ID.
func (*CurrentWeatherData) CurrentByName ¶
func (w *CurrentWeatherData) CurrentByName(location string) error
CurrentByName will provide the current weather with the provided location name.
func (*CurrentWeatherData) CurrentByZip ¶
func (w *CurrentWeatherData) CurrentByZip(zip int, countryCode string) error
CurrentByZip will provide the current weather for the provided zip code.
func (*CurrentWeatherData) SetLang ¶
func (w *CurrentWeatherData) SetLang(lang string) error
SetLang allows you to set the language responses will be displayed as. This isn't part of the NewCurrent call because it'd keep it easier to go with API defaults and adjust if explicitly called.
type Forecast3HData ¶
type Forecast3HData struct { COD string `json:"cod"` Message float64 `json:"message"` City City `json:"city"` Cnt int `json:"cnt"` List []Forecast3HList `json:"list"` Unit string Lang string }
ForecastWeatherData will hold returned data from queries
func NewForecast3H ¶
func NewForecast3H(unit, lang string) (*Forecast3HData, error)
NewForecast returns a new HistoricalWeatherData pointer with the supplied arguments.
func (*Forecast3HData) ByCoordinates ¶
func (f *Forecast3HData) ByCoordinates(location *Coordinates, days int) error
ByCoordinates will provide a forecast for the coordinates ID give for the number of days given.
func (*Forecast3HData) ByID ¶
func (f *Forecast3HData) ByID(id, days int) error
ByID will provide a forecast for the location ID give for the number of days given.
type Forecast3HList ¶
type Forecast3HList struct { Dt int `json:"dt"` Main Main `json:"main"` Weather []Weather `json:"weather"` Clouds Clouds `json:"clouds"` Wind Wind `json:"wind"` Rain Rain `json:"rain"` Snow Snow `json:"snow"` DtTxt string `json:"dt_txt "` }
Forecast5D3HList holds specific query data
type ForecastSys ¶
type ForecastSys struct {
Population int `json:"population"`
}
ForecastSys area population
type ForecastWeatherData ¶
type ForecastWeatherData struct { COD string `json:"cod"` Message float64 `json:"message"` City City `json:"city"` Cnt int `json:"cnt"` List []ForecastWeatherList `json:"list"` Unit string Lang string }
ForecastWeatherData will hold returned data from queries
func NewForecast ¶
func NewForecast(unit, lang string) (*ForecastWeatherData, error)
NewForecast returns a new HistoricalWeatherData pointer with the supplied arguments.
func (*ForecastWeatherData) DailyByCoordinates ¶
func (f *ForecastWeatherData) DailyByCoordinates(location *Coordinates, days int) error
DailyByCoordinates will provide a forecast for the coordinates ID give for the number of days given.
func (*ForecastWeatherData) DailyByID ¶
func (f *ForecastWeatherData) DailyByID(id, days int) error
DailyByID will provide a forecast for the location ID give for the number of days given.
func (*ForecastWeatherData) DailyByName ¶
func (f *ForecastWeatherData) DailyByName(location string, days int) error
DailyByName will provide a forecast for the location given for the number of days given.
type ForecastWeatherList ¶
type ForecastWeatherList struct { Dt int `json:"dt"` Temp Temperature `json:"temp"` Pressure float64 `json:"pressure"` Humidity int `json:"humidity"` Weather []Weather `json:"weather"` Speed float64 `json:"speed"` Deg int `json:"deg"` Clouds int `json:"clouds"` Snow float64 `json:"snow"` Rain float64 `json:"rain"` }
ForecastWeatherList holds specific query data
type HistoricalParameters ¶
type HistoricalParameters struct { Start int64 // Data start (unix time, UTC time zone) End int64 // Data end (unix time, UTC time zone) Cnt int // Amount of returned data (one per hour, can be used instead of Data end) }
HistoricalParameters struct holds the (optional) fields to be supplied for historical data requests.
type HistoricalWeatherData ¶
type HistoricalWeatherData struct { Message string `json:"message"` Cod int `json:"cod"` CityData int `json:"city_data"` CalcTime float64 `json:"calctime"` Cnt int `json:"cnt"` List []WeatherHistory `json:"list"` Unit string }
HistoricalWeatherData struct is where the JSON is unmarshaled to when receiving data for a historical request.
func NewHistorical ¶
func NewHistorical(unit string) (*HistoricalWeatherData, error)
NewHistorical returns a new HistoricalWeatherData pointer with the supplied arguments.
func (*HistoricalWeatherData) HistoryByID ¶
func (h *HistoricalWeatherData) HistoryByID(id int, hp ...*HistoricalParameters) error
HistoryByID will return the history for the provided location ID
func (*HistoricalWeatherData) HistoryByName ¶
func (h *HistoricalWeatherData) HistoryByName(location string) error
HistoryByName will return the history for the provided location
type Main ¶
type Main struct { Temp float64 `json:"temp"` TempMin float64 `json:"temp_min"` TempMax float64 `json:"temp_max"` Pressure float64 `json:"pressure"` SeaLevel float64 `json:"sea_level"` GrndLevel float64 `json:"grnd_level"` Humidity int `json:"humidity"` }
Main struct contains the temperates, humidity, pressure for the request.
type Sys ¶
type 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"` }
Sys struct contains general information about the request and the surrounding area for where the request was made.
type Temperature ¶
type Temperature 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"` }
Temperature holds returned termperate sure stats
type Weather ¶
type Weather struct { ID int `json:"id"` Main string `json:"main"` Description string `json:"description"` Icon string `json:"icon"` }
Weather struct holds high-level, basic info on the returned data.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
_examples
|
|
cli
weather.go This application will go out and get the weather for the given location and display it in the given data units (fahrenheit, celcius, or kelvin).
|
weather.go This application will go out and get the weather for the given location and display it in the given data units (fahrenheit, celcius, or kelvin). |
web
Example of creating a web based application purely using the net/http package to display weather information and Twitter Bootstrap so it doesn't look like it's '92.
|
Example of creating a web based application purely using the net/http package to display weather information and Twitter Bootstrap so it doesn't look like it's '92. |