Documentation
¶
Overview ¶
domain.go exposes waqi as a kit Domain: a driver that a multi-domain host (ant) enables with a single blank import,
import _ "github.com/tamnd/waqi-cli/waqi"
exactly as a database/sql program enables a driver with `import _ "github.com/lib/pq"`. The init below registers it; the host then dereferences waqi:// URIs by routing to the operations Register installs. The same Domain also builds the standalone waqi binary (see cmd/waqi), so the binary and a host share one source of truth.
Package waqi is the library behind the waqi command line: the HTTP client, request shaping, and typed data models for api.waqi.info.
The Client sets a real User-Agent, paces requests, and retries transient failures (429 and 5xx) with exponential backoff. Two operations are provided: get real-time air quality for a city (Feed) and search stations by keyword.
Index ¶
Constants ¶
const Host = "api.waqi.info"
Host is the site this client talks to.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to api.waqi.info over HTTP.
type Config ¶
type Config struct {
BaseURL string
UserAgent string
Token string // default "demo"
Rate time.Duration
Timeout time.Duration
Retries int
}
Config holds tunable knobs for the HTTP client.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns sensible defaults for production use.
type Domain ¶
type Domain struct{}
Domain is the waqi driver. It carries no state; the per-run client is built by the factory Register hands kit.
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 SearchResult ¶
type SearchResult struct {
UID int `kit:"id" json:"uid"`
Name string `json:"name"`
AQI string `json:"aqi"`
Lat string `json:"lat"`
Lon string `json:"lon"`
}
SearchResult is one entry returned by the search endpoint.
type Station ¶
type Station struct {
City string `kit:"id" json:"city"`
AQI int `json:"aqi"`
Dominant string `json:"dominant_pollutant"` // dominentpol field
PM25 string `json:"pm25"` // iaqi.pm25.v, formatted "%.1f" or "-"
PM10 string `json:"pm10"` // iaqi.pm10.v
O3 string `json:"o3"` // iaqi.o3.v
NO2 string `json:"no2"` // iaqi.no2.v
SO2 string `json:"so2"` // iaqi.so2.v
Temp string `json:"temp_c"` // iaqi.t.v
Updated string `json:"updated"` // time.s
}
Station holds the parsed air quality data for one monitoring station. String fields use "%.1f" formatting or "-" when the measurement is absent.