wikipedia

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

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 NewClient

func NewClient(opts ...Option) (*Client, error)

NewClient returns a new instance of the Wikipedia client.

func (*Client) GetPage added in v0.2.0

func (c *Client) GetPage(ctx context.Context, id int, opts ...GetPageOption) (*Page, error)

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.

func (*Client) Search

func (c *Client) Search(
	ctx context.Context,
	query string,
	options ...func(searchOptions *SearchOptions),
) ([]string, error)

Search searches the Wikipedia for the given query.

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

func WithLanguage(language string) Option

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

func WithUserAgent(userAgent string) Option

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

type PageContent struct {
	Page       *Page
	Content    string
	RevisionID int
	ParentID   int
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL