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
- type Article
- type Client
- func (c *Client) Articles(ctx context.Context, search, site string, limit int, featured bool) ([]*Article, error)
- func (c *Client) Blogs(ctx context.Context, search string, limit int) ([]*Article, error)
- func (c *Client) Get(ctx context.Context, rawURL string) ([]byte, error)
- func (c *Client) Reports(ctx context.Context, search string, limit int) ([]*Article, error)
- type Config
- type Domain
Constants ¶
const BaseURL = "https://" + Host
BaseURL is the root every request is built from.
const DefaultUserAgent = "spaceflightnews-cli/0.1 (tamnd87@gmail.com)"
DefaultUserAgent identifies the client honestly to the API.
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 (*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.
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.
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 ¶
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.