openmeteo

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

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

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

func WeatherCodeDesc(code int) string

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 NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

func (*Client) AirQualityAt added in v0.1.1

func (c *Client) AirQualityAt(ctx context.Context, lat, lon float64) (AirQuality, error)

AirQualityAt fetches current air quality for the given coordinates.

func (*Client) Current added in v0.1.1

func (c *Client) Current(ctx context.Context, lat, lon float64) (*CurrentWeather, error)

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

func (c *Client) Forecast(ctx context.Context, lat, lon float64, days int) ([]DailyForecast, error)

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

func (c *Client) Geocode(ctx context.Context, name string, count int) ([]GeoResult, error)

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) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns an input into the canonical (type, id).

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.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate returns the live https URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

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.

Jump to

Keyboard shortcuts

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