Documentation
¶
Overview ¶
Package nws is the library behind the nws command line: the HTTP client, request shaping, and the typed data models for the US National Weather Service public API (api.weather.gov). No API key required.
Index ¶
- type Alert
- type Client
- func (c *Client) Alerts(ctx context.Context, state string, limit int) ([]Alert, error)
- func (c *Client) Forecast(ctx context.Context, lat, lon string, hourly bool) ([]ForecastPeriod, error)
- func (c *Client) Points(ctx context.Context, lat, lon string) (GridPoint, error)
- func (c *Client) Stations(ctx context.Context, state string, limit int) ([]Station, error)
- type Config
- type Domain
- type ForecastPeriod
- type GridPoint
- type Station
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Alert ¶
type Alert struct {
ID string `kit:"id" json:"id"`
Event string `json:"event"`
Severity string `json:"severity"`
Area string `json:"area"`
Headline string `json:"headline"`
Onset string `json:"onset"`
Expires string `json:"expires"`
}
Alert is one active weather alert.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to api.weather.gov.
func (*Client) Forecast ¶
func (c *Client) Forecast(ctx context.Context, lat, lon string, hourly bool) ([]ForecastPeriod, error)
Forecast returns 7-day (or hourly) forecast periods for a lat/lon. It first resolves the NWS grid via /points, then fetches /gridpoints/forecast.
type Config ¶
type Config struct {
BaseURL string
UserAgent string
Rate time.Duration
Retries int
Timeout time.Duration
}
Config holds tunables for the NWS client.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config with conservative NWS-appropriate defaults. NWS blocks requests that carry no User-Agent.
type Domain ¶
type Domain struct{}
Domain is the NWS 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 identity reused for the binary's help and version.
type ForecastPeriod ¶
type ForecastPeriod struct {
Name string `kit:"id" json:"name"`
StartTime string `json:"start_time"`
Temperature int `json:"temperature"`
TempUnit string `json:"temp_unit"`
WindSpeed string `json:"wind_speed"`
WindDir string `json:"wind_direction"`
ShortForecast string `json:"short_forecast"`
}
ForecastPeriod is one period in a 7-day or hourly forecast.
type GridPoint ¶ added in v0.1.1
type GridPoint struct {
GridID string `kit:"id" json:"grid_id"`
GridX int `json:"grid_x"`
GridY int `json:"grid_y"`
City string `json:"city"`
State string `json:"state"`
ForecastURL string `json:"forecast_url"`
}
GridPoint is the NWS grid info for a lat/lon coordinate.