Documentation ¶
Index ¶
- type Action
- type Client
- func (c *Client) GetPage(ctx context.Context, id int, opts ...GetPageOption) (*Page, error)
- func (c *Client) GetPageByTitle(ctx context.Context, title string, opts ...GetPageOption) (*Page, error)
- func (c *Client) GetPageContent(ctx context.Context, id int, opts ...GetPageOption) (*PageContent, error)
- func (c *Client) GetPageContentByTitle(ctx context.Context, title string, opts ...GetPageOption) (*PageContent, error)
- func (c *Client) Search(ctx context.Context, query string, ...) ([]string, error)
- type GetPageOption
- type GetPageOptions
- type Option
- type Page
- type PageContent
- type SearchOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action string
Action is the action of the Wikipedia API request.
const (
ActionQuery Action = "query" // query action
)
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a client for the Wikipedia API requests. Wikipedia API main page: https://www.mediawiki.org/wiki/API:Main_page Wikipedia API docs: https://en.wikipedia.org/api/rest_v1/
func (*Client) GetPage ¶ added in v0.2.0
GetPage returns a wikipedia page from the wikipedia API endpoint by given page id.
func (*Client) GetPageByTitle ¶ added in v0.2.0
func (c *Client) GetPageByTitle(ctx context.Context, title string, opts ...GetPageOption) (*Page, error)
GetPageByTitle returns a wikipedia page from the wikipedia API endpoint by given page title.
func (*Client) GetPageContent ¶ added in v0.2.0
func (c *Client) GetPageContent(ctx context.Context, id int, opts ...GetPageOption) (*PageContent, error)
GetPageContent returns a wikipedia page content from the wikipedia API endpoint by given page id.
func (*Client) GetPageContentByTitle ¶ added in v0.2.0
func (c *Client) GetPageContentByTitle(ctx context.Context, title string, opts ...GetPageOption) (*PageContent, error)
GetPageContentByTitle returns a wikipedia page content from the wikipedia API endpoint by given page title.
type GetPageOption ¶ added in v0.2.0
type GetPageOption func(*GetPageOptions)
GetPageOption is the option func for the Wikipedia page request.
func WithGetPageRedirects ¶ added in v0.2.0
func WithGetPageRedirects(r bool) GetPageOption
WithGetPageRedirects sets the redirects option for the Wikipedia page request.
type GetPageOptions ¶ added in v0.2.0
type GetPageOptions struct {
Redirects bool
}
GetPageOptions are the options for the Wikipedia page request.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option is a functional option for the Client.
func WithLanguage ¶
WithLanguage sets the language code of the API being requested. It sets url domain prefix to one of the two letter prefixes found on the [All wikipedias ordered by number of articles](http://meta.wikimedia.org/wiki/List_of_Wikipedias). For example, `en` for English (https://en.wikipedia.org), `zh` for Chinese (https://zh.wikipedia.org).
func WithUserAgent ¶
WithUserAgent sets the HTTP header User-Agent for all requests to access wikipedia API.
type Page ¶ added in v0.2.0
type Page struct { PageID int `json:"pageid"` Title string `json:"title"` HTML string `json:"html"` URL string `json:"fullurl"` RevisionID int `json:"revid"` ParentID int `json:"parentid"` Summary string `json:"summary"` CheckedImage bool `json:"checkedimage"` Images []string `json:"images"` Coordinate []float64 `json:"coordinates"` Reference []string `json:"references"` Link []string `json:"links"` Category []string `json:"categories"` Section []string `json:"sections"` SectionOffset map[string][]int `json:"sectionoffset"` Disambiguation []string `json:"disambiguation"` }
Page represents a wikipedia page info.
type PageContent ¶ added in v0.2.0
PageContent represents a wikipedia page content.
type SearchOptions ¶
type SearchOptions struct {
Limit int // the max number of results returned, default 10
}
SearchOptions are the options for the Wikipedia search request.