weather

package
v0.3.19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 14 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

View Source
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 Astronomy

type Astronomy struct {
	Sunrise TimeOfDay
	Sunset  TimeOfDay
}

Astronomy is today's sun times.

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

func FromWmoCode(code uint8) Condition

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 Distance

type Distance float32

Distance is kilometers.

func (Distance) Km

func (d Distance) Km() float32

Km is the stored value.

func (Distance) Miles

func (d Distance) Miles() float32

Miles converts.

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.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Retryable

func (e *Error) Retryable() bool

Retryable is error.rs is_retryable: transport failures, server errors, and rate limits are retried; parse, location, and key errors are not.

func (*Error) Unwrap

func (e *Error) Unwrap() error

type ErrorKind

type ErrorKind int

ErrorKind is service.rs WeatherErrorKind: what the UI shows for a failed fetch, without implementation details.

const (
	ErrOther ErrorKind = iota
	ErrAPIKeyMissing
	ErrLocationNotFound
	ErrNetwork
	ErrRateLimited
)

Error kinds.

type FetchFunc

type FetchFunc func(ctx context.Context, s Settings, now time.Time) (*Weather, error)

FetchFunc fetches one forecast: the providers, or a stand-in.

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

type Location struct {
	City    string
	Region  string
	Country string
	Lat     float64
	Lon     float64
}

Location is where the forecast is for. Coordinates passed directly resolve with an empty city and country.

type LocationQuery

type LocationQuery struct {
	Coordinates bool
	Lat, Lon    float64
	City        string
	Country     string
}

LocationQuery is what to forecast: coordinates, or a city name with an optional ISO country code.

func City

func City(name string) LocationQuery

City is a city-name query.

func Coords

func Coords(lat, lon float64) LocationQuery

Coords is a coordinate query.

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 Percentage

type Percentage uint8

Percentage is 0..100.

type Precipitation

type Precipitation float32

Precipitation is millimeters.

func (Precipitation) Inches

func (p Precipitation) Inches() float32

Inches converts.

func (Precipitation) Mm

func (p Precipitation) Mm() float32

Mm is the stored value.

type Pressure

type Pressure float32

Pressure is hectopascals.

func (Pressure) Hpa

func (p Pressure) Hpa() float32

Hpa is the stored value.

func (Pressure) InHg

func (p Pressure) InHg() float32

InHg converts.

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 New

func New(s Settings) *Service

New starts a service polling with s; Close stops it.

func NewWith

func NewWith(s Settings, fetch FetchFunc) *Service

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.

func (*Service) Configure

func (s *Service) Configure(next Settings)

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.

func (*Service) Status

func (s *Service) Status() Status

Status is the fetch lifecycle.

func (*Service) Subscribe

func (s *Service) Subscribe() (<-chan struct{}, func())

Subscribe ticks whenever Weather or Status changed.

func (*Service) Weather

func (s *Service) Weather() *Weather

Weather is the last successful fetch; nil before the first.

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 Speed

type Speed float32

Speed is km/h.

func (Speed) Kmh

func (s Speed) Kmh() float32

Kmh is the stored value.

func (Speed) Mph

func (s Speed) Mph() float32

Mph converts.

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 Temperature

type Temperature float32

Temperature is degrees Celsius.

func (Temperature) Celsius

func (t Temperature) Celsius() float32

Celsius is the stored value.

func (Temperature) Fahrenheit

func (t Temperature) Fahrenheit() float32

Fahrenheit converts.

type TimeOfDay

type TimeOfDay struct{ Hour, Minute int }

TimeOfDay is a local wall-clock time (chrono's NaiveTime at minute precision).

func (TimeOfDay) String

func (t TimeOfDay) String() string

String is HH:MM.

type UVIndex

type UVIndex uint8

UVIndex is 0..15.

func (UVIndex) RiskLevel

func (u UVIndex) RiskLevel() string

RiskLevel is the WHO band name.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL