Documentation
¶
Overview ¶
Package weather is wayle-weather: forward geocoding, the Open-Meteo, Visual Crossing, and WeatherAPI.com providers behind one model, and the polling service the bar module and dropdown read.
Index ¶
- Variables
- type Astronomy
- type Condition
- type Current
- type Daily
- type Distance
- type Error
- type ErrorKind
- type FetchFunc
- type Hourly
- type Location
- type LocationQuery
- type Percentage
- type Precipitation
- type Pressure
- type ProviderKind
- type Service
- type Settings
- type Speed
- type Status
- type StatusKind
- type Temperature
- type TimeOfDay
- type UVIndex
- type Weather
- type WindDirection
Constants ¶
This section is empty.
Variables ¶
var ( GeocodingURL = "https://geocoding-api.open-meteo.com/v1/search" OpenMeteoURL = "https://api.open-meteo.com/v1/forecast" VisualCrossingURL = "https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline" WeatherAPIURL = "https://api.weatherapi.com/v1/forecast.json" )
The endpoints; tests repoint them at a local server.
Functions ¶
This section is empty.
Types ¶
type Condition ¶
type Condition int
Condition is model.rs WeatherCondition.
const ( CondClear Condition = iota CondPartlyCloudy CondCloudy CondOvercast CondMist CondFog CondLightRain CondRain CondHeavyRain CondDrizzle CondLightSnow CondSnow CondHeavySnow CondSleet CondThunderstorm CondWindy CondHail CondUnknown )
Conditions.
func FromWmoCode ¶
FromWmoCode maps an Open-Meteo WMO weather code.
type Current ¶
type Current struct {
Temperature Temperature
FeelsLike Temperature
Condition Condition
Humidity Percentage
WindSpeed Speed
WindDirection WindDirection
WindGust Speed
UVIndex UVIndex
CloudCover Percentage
Pressure Pressure
Visibility Distance
Dewpoint Temperature
Precipitation Precipitation
IsDay bool
}
Current is the conditions now.
type Daily ¶
type Daily struct {
Date time.Time
Condition Condition
TempHigh Temperature
TempLow Temperature
TempAvg Temperature
HumidityAvg Percentage
WindSpeedMax Speed
RainChance Percentage
UVIndexMax UVIndex
PrecipitationSum Precipitation
Sunrise TimeOfDay
Sunset TimeOfDay
}
Daily is one forecast day; Date is midnight of that date in the location's zone.
type Error ¶
type Error struct {
Kind ErrorKind
// Provider names the failing endpoint ("open-meteo", "geocoding").
Provider string
// Query is the unresolved location of ErrLocationNotFound.
Query string
// Status is the HTTP status of a non-2xx reply, 0 otherwise.
Status int
// contains filtered or unexported fields
}
Error is error.rs's Error: one failed geocode or fetch.
type ErrorKind ¶
type ErrorKind int
ErrorKind is service.rs WeatherErrorKind: what the UI shows for a failed fetch, without implementation details.
type Hourly ¶
type Hourly struct {
Time time.Time
Temperature Temperature
FeelsLike Temperature
Condition Condition
Humidity Percentage
WindSpeed Speed
WindDirection WindDirection
WindGust Speed
RainChance Percentage
UVIndex UVIndex
CloudCover Percentage
Pressure Pressure
Visibility Distance
Dewpoint Temperature
Precipitation Precipitation
IsDay bool
}
Hourly is one forecast hour; Time is in the location's zone.
type Location ¶
Location is where the forecast is for. Coordinates passed directly resolve with an empty city and country.
type LocationQuery ¶
LocationQuery is what to forecast: coordinates, or a city name with an optional ISO country code.
func ParseLocation ¶
func ParseLocation(s string) LocationQuery
ParseLocation is the shell's parse_location: "lat,lon" when both halves are numbers, otherwise a city name.
type ProviderKind ¶
type ProviderKind int
ProviderKind is model.rs WeatherProviderKind.
const ( OpenMeteo ProviderKind = iota VisualCrossing WeatherAPI )
Providers.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service polls the configured provider and caches the last successful fetch. After the first poll it only fetches while something is subscribed (polling.rs skips ticks without subscribers).
func NewWith ¶
NewWith polls through fetch instead of the providers (a fixture, a demo); retries and subscriber gating behave as in New.
func (*Service) Close ¶
func (s *Service) Close()
Close stops polling and returns once the polls have, their idle connections closed.
func (*Service) Configure ¶
Configure applies new settings; unchanged settings keep the running poll (a reload that touched other keys does not refetch).
func (*Service) Refresh ¶
func (s *Service) Refresh()
Refresh restarts polling with the current settings: the dropdown's refresh and retry buttons.
type Settings ¶
type Settings struct {
Interval time.Duration
Provider ProviderKind
Location LocationQuery
VisualCrossingKey string
WeatherAPIKey string
}
Settings is everything a poll depends on (the builder's fields and the service setters). Keys are already resolved secrets; empty is unset.
type Status ¶
type Status struct {
Kind StatusKind
Error ErrorKind
Provider string
Query string
}
Status is the lifecycle with the failure of Failed: its category, the provider missing a key, and the location that did not resolve.
type StatusKind ¶
type StatusKind int
StatusKind is the fetch lifecycle (service.rs WeatherStatus).
const ( Loading StatusKind = iota Loaded Failed )
Statuses.
type TimeOfDay ¶
type TimeOfDay struct{ Hour, Minute int }
TimeOfDay is a local wall-clock time (chrono's NaiveTime at minute precision).
type Weather ¶
type Weather struct {
Current Current
Hourly []Hourly
Daily []Daily
Location Location
Astronomy Astronomy
Zone *time.Location
UpdatedAt time.Time
}
Weather is one fetch: the current conditions, the next 24 hours, the next 7 days, the resolved location, today's sunrise and sunset, and the location's time zone, which every forecast time is in.
type WindDirection ¶
type WindDirection uint16
WindDirection is degrees 0..359.
func (WindDirection) Cardinal ¶
func (d WindDirection) Cardinal() string
Cardinal is the eight-point compass name.