swpc

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

Documentation

Overview

Package swpc is the library behind the swpc command line: the HTTP client, request shaping, and the typed data models for NOAA SWPC.

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 site throws under load.

Index

Constants

View Source
const Host = "services.swpc.noaa.gov"

Host is the NOAA SWPC API hostname.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	HTTP      *http.Client
	UserAgent string
	BaseURL   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 the NOAA SWPC API over HTTP.

func NewClient

func NewClient() *Client

NewClient returns a Client with sensible defaults.

func (*Client) Get

func (c *Client) Get(ctx context.Context, rawURL string) ([]byte, error)

Get fetches rawURL and returns the response body. It paces and retries according to the client's settings.

func (*Client) GetAlerts

func (c *Client) GetAlerts(ctx context.Context, limit int) ([]SpaceAlert, error)

GetAlerts fetches current space weather alerts and watches. It returns up to limit records (all if limit <= 0).

func (*Client) GetFlares

func (c *Client) GetFlares(ctx context.Context, limit int) ([]SolarFlare, error)

GetFlares fetches solar flares from the last 7 days. Results are sorted descending by begin_time. It returns up to limit records (all if limit <= 0).

func (*Client) GetKIndex

func (c *Client) GetKIndex(ctx context.Context, limit int) ([]KIndex, error)

GetKIndex fetches the planetary K-index history. It returns the last limit records (all if limit <= 0).

func (*Client) GetSolarWind

func (c *Client) GetSolarWind(ctx context.Context) (*SolarWind, error)

GetSolarWind fetches the current solar wind speed.

type Config

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

Config holds the client configuration.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults for the SWPC client.

type Domain

type Domain struct{}

Domain is the swpc 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 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 KIndex

type KIndex struct {
	Time         string  `json:"time" kit:"id"`
	Kp           float64 `json:"kp"`
	ARunning     float64 `json:"a_running"`
	StationCount int     `json:"station_count"`
	Activity     string  `json:"activity"`
}

KIndex is one planetary K-index reading.

type SolarFlare

type SolarFlare struct {
	BeginTime  string `json:"begin_time" kit:"id"`
	MaxTime    string `json:"max_time"`
	EndTime    string `json:"end_time"`
	BeginClass string `json:"begin_class"`
	MaxClass   string `json:"max_class"`
	Satellite  int    `json:"satellite"`
}

SolarFlare is a record of a solar flare event.

type SolarWind

type SolarWind struct {
	Time        string `json:"time" kit:"id"`
	ProtonSpeed int    `json:"proton_speed_km_s"`
}

SolarWind is a solar wind speed reading.

type SpaceAlert

type SpaceAlert struct {
	ProductID string `json:"product_id" kit:"id"`
	IssuedAt  string `json:"issued_at"`
	Message   string `json:"message"`
}

SpaceAlert is a NOAA space weather alert or watch.

Jump to

Keyboard shortcuts

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