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
- type Client
- func (c *Client) Get(ctx context.Context, rawURL string) ([]byte, error)
- func (c *Client) GetAlerts(ctx context.Context, limit int) ([]SpaceAlert, error)
- func (c *Client) GetFlares(ctx context.Context, limit int) ([]SolarFlare, error)
- func (c *Client) GetKIndex(ctx context.Context, limit int) ([]KIndex, error)
- func (c *Client) GetSolarWind(ctx context.Context) (*SolarWind, error)
- type Config
- type Domain
- type KIndex
- type SolarFlare
- type SolarWind
- type SpaceAlert
Constants ¶
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 (*Client) Get ¶
Get fetches rawURL and returns the response body. It paces and retries according to the client's settings.
func (*Client) GetAlerts ¶
GetAlerts fetches current space weather alerts and watches. It returns up to limit records (all if limit <= 0).
func (*Client) GetFlares ¶
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).
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) 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.
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.