Documentation
¶
Overview ¶
Package guardian is the library behind the guardian command line: the HTTP client, request shaping, and the typed data models for The Guardian newspaper API.
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 ¶
const BaseURL = "https://content.guardianapis.com"
BaseURL is the root every request is built from.
const Host = "content.guardianapis.com"
Host is the API host this client talks to.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Article ¶
type Article struct {
ID string `json:"id" kit:"id"`
Title string `json:"title"`
Section string `json:"section"`
PublishedAt string `json:"published_at"`
Author string `json:"author"`
Trail string `json:"trail"`
URL string `json:"url"`
}
Article is a single piece of content from The Guardian.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to The Guardian content API over HTTPS.
func NewClientWithConfig ¶
NewClientWithConfig returns a Client using the provided Config.
func (*Client) ListSections ¶
ListSections returns all content sections available on The Guardian.
type Config ¶
type Config struct {
BaseURL string
APIKey string
UserAgent string
Rate time.Duration
Retries int
Timeout time.Duration
}
Config holds all tunable knobs for the client.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns sensible defaults using the official free demo key.
type Domain ¶
type Domain struct{}
Domain is the guardian 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 into a canonical (type, id). - "technology/2024/abc" (contains "/") → ("article", id) - "technology" (single token) → ("section", id) - "climate change" (contains space) → ("query", q)
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.