Categorygithub.com/ciehanski/go-wikimedia
modulepackage
1.0.0
Repository: https://github.com/ciehanski/go-wikimedia.git
Documentation: pkg.go.dev

# README

go-wikimedia

go-wikimedia is an interface to the Wikimedia (Wikipedia, Wiktionary, etc.) API implemented in the Go programming language.

This project was originally created by Patrick Mylund Nielsen. I forked his repo for my project pastime. If you notice a bug, feel free to submit an issue on this repo.

Installation

go get github.com/ciehanski/go-wikimedia

Documentation

https://godoc.org/github.com/ciehanski/go-wikimedia

or from the CLI:

go doc github.com/ciehanski/go-wikimedia

Usage

package main

import (
	"fmt"
	"log"
	"net/http"
	"net/url"
	
	"github.com/ciehanski/go-wikimedia"
)

func main() {
    wiki, err := wikimedia.New(wikimedia.Options{
    	Client:    http.DefaultClient,
    	URL:       "https://en.wikipedia.org/w/api.php",
    	UserAgent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 " +
    		"(KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36",
    })
    if err != nil {
    	log.Fatal(err.Error())
    }
    resp, err := wiki.Query(url.Values{
        "action":      {"query"},
        "prop":        {"extracts"},
        "titles":      {"Osmosis|Procrastination"},
        "exsentences": {"5"},
        "explaintext": {"1"},
        "original":    {"source"},
    })
    if err != nil {
    	log.Fatalf("Error executing query: %s", err.Error())
    }
    for _, v := range resp.Query.Pages {
    	fmt.Println(v.Title, "-", v.Extract)
    }
}

Contributing

Please feel free to contribute and submit any PRs to this project.

License

MIT

# Functions

New initializes a Wikimedia object that queries the specified API URL, e.g.

# Structs

ApiPage model struct as defined by any Wikimedia API JSON response.
ApiQuery model struct as defined by any Wikimedia API JSON response.
ApiQueryContinue model struct as defined by any Wikimedia API JSON response.
ApiQueryContinueSearch model struct as defined by any Wikimedia API JSON response.
ApiResponse model struct as defined by any Wikimedia API JSON response.
ApiSearch model struct as defined by any Wikimedia API JSON response.
ApiSearchInfo model struct as defined by any Wikimedia API JSON response.
Options is a collection of configurable options for the Wikimedia client.
Original model struct as defined by any Wikimedia API JSON response.
Thumbnail model struct as defined by any Wikimedia API JSON response.
Wikimedia is an API client struct.