airquality

package
v0.1.0 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: 8 Imported by: 0

Documentation

Overview

Package airquality is the library behind the airquality command line: the HTTP client, request shaping, and the typed data models for the Open-Meteo Air Quality API.

The Client sets a real User-Agent, paces requests, and retries transient failures (429 and 5xx). All endpoint calls and JSON decoding build on top.

Index

Constants

View Source
const BaseURL = "https://" + Host

BaseURL is the root every request is built from.

View Source
const DefaultUserAgent = "airquality/dev (+https://github.com/tamnd/airquality-cli)"

DefaultUserAgent identifies the client to Open-Meteo.

View Source
const Host = "air-quality-api.open-meteo.com"

Host is the Open-Meteo Air Quality API host.

Variables

This section is empty.

Functions

This section is empty.

Types

type AirQuality

type AirQuality struct {
	Time            string  `kit:"id" json:"time"`
	PM10            float64 `json:"pm10"`
	PM25            float64 `json:"pm2_5"`
	CarbonMonoxide  float64 `json:"carbon_monoxide"`
	Ozone           float64 `json:"ozone"`
	SulphurDioxide  float64 `json:"sulphur_dioxide"`
	NitrogenDioxide float64 `json:"nitrogen_dioxide"`
	UVIndex         float64 `json:"uv_index"`
}

AirQuality holds one hour of air quality measurements at a location.

type Client

type Client struct {
	HTTP      *http.Client
	UserAgent string
	// Rate is the minimum gap between requests. Zero means no pacing.
	Rate    time.Duration
	Retries int
	// contains filtered or unexported fields
}

Client talks to the Open-Meteo Air Quality API over HTTP.

func NewClient

func NewClient() *Client

NewClient returns a Client with sensible defaults: a 30s timeout, a 200ms minimum gap between requests, and five retries on transient errors.

func (*Client) Forecast

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

Forecast fetches hourly air quality for a lat/lon coordinate over the given number of forecast days (1-7). Results are truncated to limit records.

func (*Client) Get

func (c *Client) Get(ctx context.Context, url string) ([]byte, error)

Get fetches url and returns the response body. It paces and retries according to the client's settings. The body is read fully and closed here.

type Domain

type Domain struct{}

Domain is the airquality driver.

func (Domain) Classify

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

Classify turns a lat,lon pattern or a full URL 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 is the inverse: 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.

Jump to

Keyboard shortcuts

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