nws

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: 9 Imported by: 0

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

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 NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client with the provided config.

func (*Client) Alerts

func (c *Client) Alerts(ctx context.Context, state string, limit int) ([]Alert, error)

Alerts returns active weather alerts for a 2-letter US state code.

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.

func (*Client) Points added in v0.1.1

func (c *Client) Points(ctx context.Context, lat, lon string) (GridPoint, error)

Points returns grid info for a lat/lon coordinate.

func (*Client) Stations

func (c *Client) Stations(ctx context.Context, state string, limit int) ([]Station, error)

Stations returns weather observation stations for a 2-letter US state code.

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

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

Classify turns an input into (type, id) for ant URI routing.

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, 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 API URL for a (type, id) pair.

func (Domain) Register

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

Register installs the client factory and every NWS operation onto app.

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.

type Station

type Station struct {
	ID       string `kit:"id" json:"id"`
	Name     string `json:"name"`
	TimeZone string `json:"timezone"`
	State    string `json:"state"`
}

Station is a weather observation station.

Jump to

Keyboard shortcuts

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