Documentation
¶
Overview ¶
Package commons is the library behind the commons command line: the HTTP client, request shaping, wire types, and the typed data models for Wikimedia Commons.
The Client is the spine every command shares. It sets a real User-Agent (required by Wikimedia policy), paces requests so a busy session stays polite, and retries the transient failures (429 and 5xx) that any public API throws under load. Build your endpoint calls and JSON decoding on top of it.
Index ¶
- Constants
- type Category
- type Client
- func (c *Client) GetFile(ctx context.Context, title string) (*File, error)
- func (c *Client) ListCategory(ctx context.Context, name string, limit int) ([]*Category, error)
- func (c *Client) RecentUploads(ctx context.Context, limit int) ([]*File, error)
- func (c *Client) SearchFiles(ctx context.Context, query string, limit, offset int) ([]*File, error)
- type Config
- type Domain
- type File
Constants ¶
const APIBase = "https://commons.wikimedia.org/w/api.php"
APIBase is the Wikimedia Commons MediaWiki API endpoint.
const BaseURL = "https://" + Host
BaseURL is the root of the wiki, used to build human-readable page URLs.
const Host = "commons.wikimedia.org"
Host is the commons hostname used for URI matching in domain.go.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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 Wikimedia Commons API over HTTP.
func (*Client) GetFile ¶
GetFile fetches file info and metadata for a single file. title should be the bare filename without "File:" prefix; the prefix is added automatically.
func (*Client) ListCategory ¶
ListCategory lists files that belong to a Wikimedia Commons category. name should be the bare category name without "Category:" prefix.
func (*Client) RecentUploads ¶
RecentUploads returns recently uploaded files.
type Config ¶
type Config struct {
BaseURL string
UserAgent string
Rate time.Duration
Timeout time.Duration
Retries int
}
Config holds tunable parameters for the Client.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the recommended Config for production use.
type Domain ¶
type Domain struct{}
Domain is the Wikimedia Commons 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 the canonical (uriType, id). For file URLs and "File:" prefixed titles the type is "file". For category URLs the type is "category".
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.
type File ¶
type File struct {
FileName string `json:"file_name" kit:"id"`
Title string `json:"title"`
PageID int `json:"page_id"`
URL string `json:"url,omitempty"`
Size int `json:"size,omitempty"`
MediaType string `json:"media_type,omitempty"`
Description string `json:"description,omitempty"`
Author string `json:"author,omitempty"`
License string `json:"license,omitempty"`
Date string `json:"date,omitempty"`
}
File is a Wikimedia Commons media file. FileName is the bare name without "File:" prefix; it doubles as the kit id.