nps

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

Documentation

Overview

Package nps is the library behind the nps command line: the HTTP client, request shaping, and the typed data models for the National Park Service (NPS) public API.

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

View Source
const Host = "developer.nps.gov"

Host is the NPS API host. Used in domain.go for the driver's host list.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alert

type Alert struct {
	ID          string `json:"id"`
	Title       string `json:"title"`
	Description string `json:"description"`
	Category    string `json:"category"`
	ParkCode    string `json:"parkCode"`
	URL         string `json:"url,omitempty"`
}

Alert is returned by the /alerts endpoint.

type AlertsInput

type AlertsInput struct {
	ParkCode string
	Limit    int
	Start    int
}

AlertsInput controls the /alerts query.

type Campground

type Campground struct {
	ID              string `json:"id"`
	Name            string `json:"name"`
	ParkCode        string `json:"parkCode"`
	Description     string `json:"description"`
	URL             string `json:"url,omitempty"`
	Latitude        string `json:"latitude,omitempty"`
	Longitude       string `json:"longitude,omitempty"`
	ReservableSites string `json:"numberOfSitesReservable,omitempty"`
	WalkupSites     string `json:"numberOfSitesFirstComeFirstServe,omitempty"`
}

Campground is returned by the /campgrounds endpoint.

type CampgroundsInput

type CampgroundsInput struct {
	State    string
	ParkCode string
	Limit    int
	Start    int
}

CampgroundsInput controls the /campgrounds query.

type Client

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

Client talks to the NPS API over HTTP.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client using the provided Config.

func (*Client) Alerts

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

Alerts fetches alerts from the NPS API.

func (*Client) Campgrounds

func (c *Client) Campgrounds(ctx context.Context, in CampgroundsInput) ([]Campground, error)

Campgrounds fetches campgrounds from the NPS API.

func (*Client) Parks

func (c *Client) Parks(ctx context.Context, in ParksInput) ([]Park, error)

Parks fetches parks from the NPS API.

func (*Client) VisitorCenters

func (c *Client) VisitorCenters(ctx context.Context, in VisitorCentersInput) ([]VisitorCenter, error)

VisitorCenters fetches visitor centers from the NPS API.

type Config

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

Config holds all tunable knobs for the Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults for the NPS API.

type Domain

type Domain struct{}

Domain is the nps 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 any accepted 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 is the inverse: 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 Park

type Park struct {
	ID          string `json:"id"`
	Code        string `json:"parkCode"`
	Name        string `json:"fullName"`
	Description string `json:"description"`
	States      string `json:"states"`
	URL         string `json:"url"`
	LatLong     string `json:"latLong,omitempty"`
}

Park is a national park unit returned by the /parks endpoint.

type ParksInput

type ParksInput struct {
	State    string // two-letter state code, e.g. "CA"
	ParkCode string // e.g. "grca"
	Limit    int    // 0 means server default (50)
	Start    int    // pagination offset
}

ParksInput controls the /parks query.

type VisitorCenter

type VisitorCenter struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	ParkCode    string `json:"parkCode"`
	Description string `json:"description"`
	URL         string `json:"url,omitempty"`
	Latitude    string `json:"latitude,omitempty"`
	Longitude   string `json:"longitude,omitempty"`
}

VisitorCenter is returned by the /visitor-centers endpoint.

type VisitorCentersInput

type VisitorCentersInput struct {
	State    string
	ParkCode string
	Limit    int
	Start    int
}

VisitorCentersInput controls the /visitor-centers query.

Jump to

Keyboard shortcuts

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