Documentation
¶
Overview ¶
Package openmeteo exposes the Open-Meteo weather API as a kit Domain driver.
A multi-domain host (ant) enables it with a single blank import:
import _ "github.com/tamnd/openmeteo-cli/openmeteo"
The same Domain also builds the standalone openmeteo binary (see cli.NewApp).
Package openmeteo is the library behind the openmeteo command line: the HTTP client, request shaping, and the typed data models for the Open-Meteo weather API (api.open-meteo.com).
Open-Meteo is a free, open-source weather API providing current conditions and multi-day forecasts for any geographic coordinate. No API key or registration is required. Data is sourced from national meteorological services and refreshed every 15 minutes.
Index ¶
- Constants
- func WeatherCodeDesc(code int) string
- type AirQuality
- type Client
- func (c *Client) AirQualityAt(ctx context.Context, lat, lon float64) (AirQuality, error)
- func (c *Client) Current(ctx context.Context, lat, lon float64) (*CurrentWeather, error)
- func (c *Client) Forecast(ctx context.Context, lat, lon float64, days int) ([]DailyForecast, error)
- func (c *Client) Geocode(ctx context.Context, name string, count int) ([]GeoResult, error)
- func (c *Client) HourlyForecast(ctx context.Context, lat, lon float64, days int) ([]HourlySlice, error)
- type Config
- type CurrentWeather
- type DailyForecast
- type Domain
- type GeoResult
- type HourlySlice
Constants ¶
const Host = "api.open-meteo.com"
Host is the API host this client talks to.
Variables ¶
This section is empty.
Functions ¶
func WeatherCodeDesc ¶ added in v0.1.1
WeatherCodeDesc maps a WMO weather interpretation code to a human description.
Types ¶
type AirQuality ¶ added in v0.1.1
type AirQuality struct {
PM10 float64 `json:"pm10"`
PM25 float64 `json:"pm2_5"`
CO float64 `json:"carbon_monoxide"`
NO2 float64 `json:"nitrogen_dioxide"`
Ozone float64 `json:"ozone"`
EuroAQI float64 `json:"european_aqi"`
}
AirQuality holds current air quality measurements.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to the Open-Meteo API over HTTP.
func (*Client) AirQualityAt ¶ added in v0.1.1
AirQualityAt fetches current air quality for the given coordinates.
func (*Client) Current ¶ added in v0.1.1
Current fetches current weather conditions for the given coordinates. The returned CurrentWeather contains temperature, wind, humidity, pressure, and a WMO weather code with a human-readable description.
func (*Client) Forecast ¶ added in v0.1.1
Forecast fetches a daily forecast for the given coordinates. days must be 1–16; values ≤ 0 default to 7, values > 16 are clamped to 16.
func (*Client) Geocode ¶ added in v0.1.1
Geocode resolves a city name to geographic coordinates. Returns up to count results ordered by population.
func (*Client) HourlyForecast ¶ added in v0.1.1
func (c *Client) HourlyForecast(ctx context.Context, lat, lon float64, days int) ([]HourlySlice, error)
HourlyForecast fetches an hourly forecast for the given coordinates. days must be 1–16; values <= 0 default to 3, values > 16 are clamped to 16.
type Config ¶ added in v0.1.1
type Config struct {
BaseURL string
GeoURL string
AirURL string
UserAgent string
Rate time.Duration
Timeout time.Duration
Retries int
}
Config holds all tunable parameters for the Client.
func DefaultConfig ¶ added in v0.1.1
func DefaultConfig() Config
DefaultConfig returns a Config with sensible defaults.
type CurrentWeather ¶ added in v0.1.1
type CurrentWeather struct {
Time string `json:"time"`
TempC float64 `json:"temp_c"`
WindKph float64 `json:"wind_kph"`
WindDir int `json:"wind_dir"` // degrees (0 if not requested)
Humidity int `json:"humidity"` // % (0 if not requested)
Pressure float64 `json:"pressure_hpa"` // hPa
WeatherCode int `json:"weather_code"` // WMO code
Description string `json:"description"` // from WMO code
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
Timezone string `json:"timezone"`
}
CurrentWeather holds the current weather conditions for a location.
type DailyForecast ¶ added in v0.1.1
type DailyForecast struct {
Rank int `json:"rank"`
Date string `json:"date"`
TempMaxC float64 `json:"temp_max_c"`
TempMinC float64 `json:"temp_min_c"`
PrecipMM float64 `json:"precip_mm"`
WindMaxKph float64 `json:"wind_max_kph"`
WeatherCode int `json:"weather_code"`
Description string `json:"description"`
}
DailyForecast holds the forecast for a single day.
type Domain ¶
type Domain struct{}
Domain is the openmeteo driver.
func (Domain) Info ¶
func (Domain) Info() kit.DomainInfo
Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.
type GeoResult ¶ added in v0.1.1
type GeoResult struct {
ID int `json:"id"`
Name string `json:"name"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
Country string `json:"country"`
CountryCode string `json:"country_code"`
Timezone string `json:"timezone"`
}
GeoResult is one result from the geocoding API.
type HourlySlice ¶ added in v0.1.1
type HourlySlice struct {
Time string `json:"time"`
Temperature float64 `json:"temperature_2m"`
RelativeHumidity int `json:"relative_humidity_2m"`
PrecipitationProbability int `json:"precipitation_probability"`
WindSpeed float64 `json:"wind_speed_10m"`
}
HourlySlice is one hour's weather data after transposing the parallel arrays.