spaceflightnews

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 spaceflightnews is the library behind the spaceflightnews command line: the HTTP client, request shaping, and the typed data models for the Spaceflight News API (https://api.spaceflightnewsapi.net/v4/).

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 BaseURL = "https://" + Host

BaseURL is the root every request is built from.

View Source
const DefaultUserAgent = "spaceflightnews-cli/0.1 (tamnd87@gmail.com)"

DefaultUserAgent identifies the client honestly to the API.

View Source
const Host = "api.spaceflightnewsapi.net"

Host is the API hostname this client talks to, and the host the URI driver in domain.go claims.

Variables

This section is empty.

Functions

This section is empty.

Types

type Article

type Article struct {
	ID          int    `kit:"id" json:"id"`
	Title       string `json:"title"`
	NewsSite    string `json:"news_site"`
	PublishedAt string `json:"published_at"`
	Summary     string `json:"summary"`
	URL         string `json:"url"`
}

Article is a space news article, blog post, or report from the API.

type Client

type Client struct {
	HTTP      *http.Client
	UserAgent string
	BaseURL   string
	Rate      time.Duration
	Retries   int
	// contains filtered or unexported fields
}

Client talks to the Spaceflight News API over HTTPS.

func NewClient

func NewClient() *Client

NewClient returns a Client with sensible defaults.

func (*Client) Articles

func (c *Client) Articles(ctx context.Context, search, site string, limit int, featured bool) ([]*Article, error)

Articles lists space news articles. search and site may be empty. featured filters to featured articles only when true.

func (*Client) Blogs

func (c *Client) Blogs(ctx context.Context, search string, limit int) ([]*Article, error)

Blogs lists space blog posts. search may be empty.

func (*Client) Get

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

Get fetches url and returns the response body. It paces and retries according to the client settings. The body is read fully and closed here.

func (*Client) Reports

func (c *Client) Reports(ctx context.Context, search string, limit int) ([]*Article, error)

Reports lists spaceflight reports. search may be empty.

type Config

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

Config holds the tunable parameters for the client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns production-safe defaults.

type Domain

type Domain struct{}

Domain is the Spaceflight News 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 is a no-op resolver for this API domain; resources are not addressable by a single id the way HTML-scraped sites are.

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

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

Jump to

Keyboard shortcuts

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