Documentation ¶
Overview ¶
Package weather provides a data source for weather informations.
Index ¶
- Constants
- Variables
- func FormatField(template *cdtype.Template, list []string, data interface{}) (string, error)
- func FormatSun(sunrise, sunset string, time24H bool) (sunrise2, sunset2 string, isNight bool, e error)
- func FormatTemplate(template *cdtype.Template, funcName string, data interface{}) (string, error)
- type BackendID
- type Config
- type Current
- type Day
- type Forecast
- type Loc
- type Part
- type Search
- type Weather
Constants ¶
const ( WeatherComURLBase = "http://wxdata.weather.com/wxdata" WeatherComSuffixCurrent = "/weather/local/%s?cc=*" WeatherComSuffixForecast = "/weather/local/%s?dayf=%d" WeatherComSuffixCelcius = "&unit=m" )
URL for backend data.
const ( URLWeatherComHour = "http://www.weather.com/weather/hourbyhour/graph/%s" URLWeatherComDetail = "http://www.weather.com/weather/tenday/%s" )
URL for webpages to open.
const DegreeSymbol = "°"
DegreeSymbol needs to be added before unit temperature (C or F).
Variables ¶
var ( ErrMissingConfObject = errors.New("weather #1: conf object missing") ErrMissingLocationCode = errors.New("weather #2: location missing") ValueMissing = "N/A" )
Weather errors.
Functions ¶
func FormatField ¶
FormatField formats a list of fields with the given template.
It's a callback from the template, where the list of fields to display is set. With this method, we can translate titles, align data and allow custom templating for the user.
Types ¶
type BackendID ¶
type BackendID int
BackendID represents the reference for a backend source of weather data.
type Config ¶
type Config struct { LocationCode string // hidden in conf UseCelcius bool // format temp celcius or fahrenheit Time24H bool // format time 24H or 12H (AM/PM). DisplayCurrentIcon bool // current weather. NbDays int // forecast (next days). }
Config defines the weather data source configuration.
type Current ¶
type Current struct { UnitDistance string `xml:"head>ud"` UnitPressure string `xml:"head>up"` UnitSpeed string `xml:"head>us"` UnitTemp string `xml:"head>ut"` LocName string `xml:"loc>dnam"` Sunrise string `xml:"loc>sunr"` Sunset string `xml:"loc>suns"` UpdateTime string `xml:"cc>lsup"` Observatory string `xml:"cc>obst"` TempReal int `xml:"cc>tmp"` TempFelt int `xml:"cc>flik"` WeatherDescription string `xml:"cc>t"` WeatherIcon string `xml:"cc>icon"` Pressure string `xml:"cc>bar>r"` PressureDescription string `xml:"cc>bar>d"` WindSpeed string `xml:"cc>wind>s"` WindDirection string `xml:"cc>wind>t"` Humidity string `xml:"cc>hmid"` Visibility string `xml:"cc>vis"` MoonIcon int `xml:"cc>moon>icon"` UVi int `xml:"cc>uv>i"` UVDescription string `xml:"cc>uv>t"` // Template stuff Template *cdtype.Template // template for the field formater. TxtUpdateTime string // formated (h24) UpdateTime TxtSunrise string // formated (h24) Sunrise TxtSunset string // formated (h24) Sunset IsNight bool }
Current contains weather data for the current day.
type Day ¶
type Day struct { Date string `xml:"dt,attr"` DayName string `xml:"t,attr"` DayCount string `xml:"d,attr"` Sunrise string `xml:"sunr"` Sunset string `xml:"suns"` TempMin string `xml:"low"` TempMax string `xml:"hi"` Part []Part `xml:"part"` // Template stuff MonthDay int // day number in the month. TxtSunrise string // formated (h24) Sunrise TxtSunset string // formated (h24) Sunset }
Day defines weather forecast data for one of the following day.
type Forecast ¶
type Forecast struct { Ver string `xml:"ver,attr"` Ur string `xml:"head>ur"` UnitDistance string `xml:"head>ud"` UnitPressure string `xml:"head>up"` UnitSpeed string `xml:"head>us"` UnitTemp string `xml:"head>ut"` Locale string `xml:"head>locale"` Form string `xml:"head>form"` Tm string `xml:"loc>tm"` LocName string `xml:"loc>dnam"` Lon string `xml:"loc>lon"` Lat string `xml:"loc>lat"` Zone string `xml:"loc>zone"` UpdateTime string `xml:"dayf>lsup"` Days []Day `xml:"dayf>day"` // Template stuff Template *cdtype.Template // template for the field formater. *Day // requested day *Part // requested part of day }
Forecast defines weather forecast data for the following days.
type Loc ¶
type Loc struct { Type string `xml:"type,attr"` Name string `xml:",chardata"` ID string `xml:"id,attr"` }
Loc represents a location found in the search location query.
func FindLocation ¶
FindLocation asks the server the list of locations matching the given name.
type Part ¶
type Part struct { Period string `xml:"p,attr"` WeatherDescription string `xml:"t"` WindDegree string `xml:"wind>d"` WindSpeed string `xml:"wind>s"` WindDirection string `xml:"wind>t"` Humidity string `xml:"hmid"` WeatherIcon string `xml:"icon"` PrecipitationProba string `xml:"ppcp"` WeatherShortDesc string `xml:"bt"` Gust string `xml:"wind>gust"` }
Part defines weather forecast data for one part (day or night) of a following day.