Documentation
¶
Overview ¶
Package ncei is the library behind the ncei command line: the HTTP client, request shaping, and the typed data models for NOAA NCEI (National Centers for Environmental Information) historical climate data.
The Client here is the spine every command shares. It sets a real User-Agent, paces requests so a busy session stays polite, and retries the transient failures (429 and 5xx) that any public API throws under load.
Index ¶
Constants ¶
const BaseURL = "https://www.ncei.noaa.gov/access/services/data/v1"
BaseURL is the root every data request is built from.
const DefaultUserAgent = "ncei/dev (+https://github.com/tamnd/ncei-cli)"
DefaultUserAgent identifies the client to NCEI.
const Host = "www.ncei.noaa.gov"
Host is the NCEI hostname.
Variables ¶
var KnownStations = []KnownStation{
{ID: "USW00094728", Name: "Central Park", Location: "New York, NY"},
{ID: "USW00094846", Name: "JFK Airport", Location: "New York, NY"},
{ID: "USW00013880", Name: "Hartsfield-Jackson Atlanta International Airport", Location: "Atlanta, GA"},
{ID: "USW00023234", Name: "Los Angeles International Airport", Location: "Los Angeles, CA"},
{ID: "USW00094741", Name: "O'Hare International Airport", Location: "Chicago, IL"},
{ID: "USW00023174", Name: "Seattle-Tacoma International Airport", Location: "Seattle, WA"},
}
KnownStations is the built-in lookup table of well-known NCEI station IDs.
Functions ¶
This section is empty.
Types ¶
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 NCEI over HTTP.
func NewClient ¶
func NewClient() *Client
NewClient returns a Client with sensible defaults: a 30s timeout, a 500ms minimum gap between requests, and three retries on transient errors.
func (*Client) Get ¶
Get fetches url and returns the response body. It paces and retries according to the client's settings. The caller owns nothing extra; the body is read fully and closed here.
func (*Client) GetDaily ¶
func (c *Client) GetDaily(ctx context.Context, station, start, end string, limit int) ([]DailyRecord, error)
GetDaily fetches daily climate summaries for the given station and date range. The limit parameter caps results; 0 means no cap.
func (*Client) GetMonthly ¶
func (c *Client) GetMonthly(ctx context.Context, station, start, end string, limit int) ([]MonthlyRecord, error)
GetMonthly fetches monthly climate summaries for the given station and date range. The limit parameter caps results; 0 means no cap.
type Config ¶
Config holds the tunable client settings returned by DefaultConfig.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns conservative defaults suitable for a public API.
type DailyRecord ¶
type DailyRecord struct {
Station string `json:"station" kit:"id"`
Date string `json:"date"`
TempMax float64 `json:"temp_max_c"`
TempMin float64 `json:"temp_min_c"`
TempAvg float64 `json:"temp_avg_c"`
Precipitation float64 `json:"precipitation_mm"`
Snow float64 `json:"snow_mm"`
}
DailyRecord holds a single daily climate summary for a station.
type Domain ¶
type Domain struct{}
Domain is the NCEI 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 KnownStation ¶
type KnownStation struct {
ID string `json:"id" kit:"id"`
Name string `json:"name"`
Location string `json:"location"`
}
KnownStation is an entry in the built-in station lookup table.
type MonthlyRecord ¶
type MonthlyRecord struct {
Station string `json:"station" kit:"id"`
Date string `json:"date"`
TempAvg float64 `json:"temp_avg_c"`
Precipitation float64 `json:"precipitation_mm"`
Snow float64 `json:"snow_mm"`
WindSpeed float64 `json:"wind_speed_ms"`
}
MonthlyRecord holds a single monthly climate summary for a station.