weather

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

Documentation

Overview

Package weather exposes the US National Weather Service API as a kit Domain driver.

A multi-domain host (ant) enables it with a single blank import:

import _ "github.com/tamnd/weather-cli/weather"

The same Domain also builds the standalone weather binary (see cli.NewApp).

Package weather is the library behind the weather command line: the HTTP client, request shaping, and the typed data models for the US National Weather Service API (api.weather.gov). No API key required.

Index

Constants

View Source
const Host = "api.weather.gov"

Host is the API host this client talks to.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alert

type Alert struct {
	ID          string `json:"id"`
	Event       string `json:"event"`
	Severity    string `json:"severity"`
	Certainty   string `json:"certainty"`
	Urgency     string `json:"urgency"`
	Headline    string `json:"headline"`
	Description string `json:"description,omitempty"`
	Instruction string `json:"instruction,omitempty"`
	Effective   string `json:"effective"`
	Expires     string `json:"expires"`
}

Alert is an active weather alert.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to the NWS API over HTTP.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

func (*Client) Alerts

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

Alerts fetches active weather alerts for the given US state abbreviation.

func (*Client) Forecast

func (c *Client) Forecast(ctx context.Context, lat, lon float64) ([]Period, error)

Forecast fetches the 7-day forecast for the given coordinates. It first calls /points to resolve the forecast URL, then fetches it.

func (*Client) Hourly

func (c *Client) Hourly(ctx context.Context, lat, lon float64) ([]Period, error)

Hourly fetches the hourly forecast for the given coordinates.

func (*Client) Stations

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

Stations fetches weather stations for the given US state abbreviation.

type Config

type Config struct {
	BaseURL   string
	UserAgent string
	Rate      time.Duration
	Timeout   time.Duration
	Retries   int
}

Config holds all tunable parameters for the Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults.

type Domain

type Domain struct{}

Domain is the weather driver.

func (Domain) Classify

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

Classify turns an input 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 returns 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.

type Period

type Period struct {
	Number           int    `json:"number"`
	Name             string `json:"name"`
	StartTime        string `json:"startTime"`
	EndTime          string `json:"endTime"`
	IsDaytime        bool   `json:"isDaytime"`
	Temperature      int    `json:"temperature"`
	TemperatureUnit  string `json:"temperatureUnit"`
	WindSpeed        string `json:"windSpeed"`
	WindDirection    string `json:"windDirection"`
	ShortForecast    string `json:"shortForecast"`
	DetailedForecast string `json:"detailedForecast,omitempty"`
}

Period is one forecast period (half-day or hourly).

type Station

type Station struct {
	StationIdentifier string  `json:"stationIdentifier"`
	Name              string  `json:"name"`
	Elevation         float64 `json:"elevation,omitempty"`
	Latitude          float64 `json:"latitude,omitempty"`
	Longitude         float64 `json:"longitude,omitempty"`
}

Station is a weather observation station.

Jump to

Keyboard shortcuts

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