Documentation
¶
Overview ¶
Package wikifeatured is the library behind the wikifeatured command line: the HTTP client, request shaping, and the typed data models for the Wikipedia Featured Content REST API (https://en.wikipedia.org/api/rest_v1/feed/).
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) Get(ctx context.Context, url string) ([]byte, error)
- func (c *Client) GetFeatured(ctx context.Context, date string) (*Featured, error)
- func (c *Client) GetMostRead(ctx context.Context, date string) ([]*Article, error)
- func (c *Client) GetNews(ctx context.Context, date string) ([]*NewsItem, error)
- func (c *Client) GetOnThisDay(ctx context.Context, date string) ([]*Event, error)
- type Domain
- type Event
- type Featured
- type NewsItem
Constants ¶
const DefaultUserAgent = "wikifeatured-cli/0.1 (tamnd87@gmail.com)"
DefaultUserAgent identifies the client to Wikipedia.
const Host = "en.wikipedia.org"
Host is the Wikipedia API host this client talks to.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Article ¶
type Article struct {
Rank int `json:"rank" kit:"id"`
Title string `json:"title"`
Views int `json:"views"`
Extract string `json:"extract"`
}
Article is one entry in the most-read list.
type Client ¶
type Client struct {
HTTP *http.Client
UserAgent string
BaseURL 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 Wikipedia Featured Content REST API over HTTP.
func (*Client) Get ¶
Get fetches a URL and returns the body. It paces and retries according to the client's settings.
func (*Client) GetFeatured ¶
GetFeatured fetches the featured article for the given date (YYYY/MM/DD).
func (*Client) GetMostRead ¶
GetMostRead fetches the most-read articles for the given date (YYYY/MM/DD).
type Domain ¶
type Domain struct{}
Domain is the Wikipedia Featured Content driver.
func (Domain) Classify ¶
Classify satisfies kit.Domain. This domain does not classify arbitrary URLs into addressable resource URIs, so we return a usage error for any input.
func (Domain) Info ¶
func (Domain) Info() kit.DomainInfo
Info describes the scheme, host, and identity.