nasa

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 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

View Source
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 NewClient

func NewClient() *Client

NewClient returns a Client with DefaultConfig settings.

func (*Client) APOD

func (c *Client) APOD(ctx context.Context, date string) (*APOD, error)

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) APODRange

func (c *Client) APODRange(ctx context.Context, start, end string) ([]APOD, error)

APODRange fetches a range of APODs between start and end (YYYY-MM-DD).

func (*Client) EPIC

func (c *Client) EPIC(ctx context.Context) ([]EPICImage, error)

EPIC fetches the latest natural-color EPIC Earth images.

func (*Client) NEOFeed

func (c *Client) NEOFeed(ctx context.Context, start, end string) ([]NEOSummary, error)

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

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

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.

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 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.

type RoverPhoto

type RoverPhoto struct {
	ID        int    `json:"id"`
	Sol       int    `json:"sol"`
	Camera    string `json:"camera"`
	ImageURL  string `json:"image_url"`
	EarthDate string `json:"earth_date"`
	RoverName string `json:"rover"`
}

RoverPhoto is one photo taken by a Mars rover.

Jump to

Keyboard shortcuts

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