Documentation
¶
Overview ¶
Package nasa is the library behind the nasa command line: the HTTP client, request shaping, and the typed data models for NASA APIs.
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. All endpoints require an API key; defaults to "DEMO_KEY" (30 req/hr). Register a free key at api.nasa.gov for 1000 req/hr.
Index ¶
- Constants
- type APOD
- type Client
- func (c *Client) APOD(ctx context.Context, date string) (*APOD, error)
- func (c *Client) APODRange(ctx context.Context, start, end string) ([]APOD, error)
- func (c *Client) EPIC(ctx context.Context) ([]EPICImage, error)
- func (c *Client) NEOFeed(ctx context.Context, start, end string) ([]NEOSummary, error)
- func (c *Client) RoverPhotos(ctx context.Context, rover string, sol, limit int) ([]RoverPhoto, error)
- type Config
- type Domain
- type EPICImage
- type NEOSummary
- type RoverPhoto
Constants ¶
const Host = "api.nasa.gov"
Host is the primary domain this driver claims for URI routing.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APOD ¶
type APOD struct {
Date string `json:"date" kit:"id"`
Title string `json:"title"`
Explanation string `json:"explanation,omitempty" kit:"body"`
MediaType string `json:"media_type"`
URL string `json:"url"`
HDURL string `json:"hd_url,omitempty"`
Copyright string `json:"copyright,omitempty"`
}
APOD is the Astronomy Picture of the Day record.
type Client ¶
type Client struct {
HTTP *http.Client
UserAgent string
APIKey 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 NASA API over HTTP.
func (*Client) APOD ¶
APOD fetches the Astronomy Picture of the Day for a specific date (YYYY-MM-DD). If date is empty, the API returns today's APOD.
func (*Client) NEOFeed ¶
NEOFeed fetches near-Earth objects between start and end dates (YYYY-MM-DD). The NASA API limits the window to 7 days.
func (*Client) RoverPhotos ¶
func (c *Client) RoverPhotos(ctx context.Context, rover string, sol, limit int) ([]RoverPhoto, error)
RoverPhotos fetches photos taken by a Mars rover on a specific Martian sol. limit <= 0 returns all photos on that sol (up to one API page, ~25 by default).
type Config ¶
type Config struct {
BaseURL string
UserAgent string
APIKey string
Rate time.Duration
Timeout time.Duration
Retries int
}
Config holds all tunable parameters for the NASA client.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns sensible defaults for the NASA API client.
type Domain ¶
type Domain struct{}
Domain is the nasa driver. It carries no state; the per-run client is built by the factory Register hands kit.
func (Domain) Classify ¶
Classify turns any accepted input — a bare date or a full api.nasa.gov URL — 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.
type EPICImage ¶
type EPICImage struct {
Identifier string `json:"identifier"`
Caption string `json:"caption,omitempty"`
Date string `json:"date"`
Lat float64 `json:"lat,omitempty"`
Lon float64 `json:"lon,omitempty"`
ImageURL string `json:"image_url,omitempty"`
}
EPICImage is one Earth image from the DSCOVR EPIC camera.
type NEOSummary ¶
type NEOSummary struct {
Date string `json:"date"`
Name string `json:"name"`
IsHazardous bool `json:"is_potentially_hazardous"`
DiameterMinKm float64 `json:"diameter_min_km,omitempty"`
DiameterMaxKm float64 `json:"diameter_max_km,omitempty"`
}
NEOSummary is a flattened record for one near-Earth object on one date.