wikilinkapi

package
v0.0.0-...-aaad7c8 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2023 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const AllLinksTemplate = `` /* 150-byte string literal not displayed */

Ex: "https://en.wikipedia.org/w/api.php?action=query&format=json&formatversion=2&gapcontinue=%22Boss%22_Tweed&gapfilterredir=nonredirects&gaplimit=max&gapnamespace=0&generator=allpages"

View Source
const LinksToTemplate = `https://%s.wikipedia.org/w/api.php?action=query&format=json&formatversion=2&pllimit=max&plnamespace=0&prop=links&titles=%s`

Ex: https://en.wikipedia.org/w/api.php?action=query&format=json&formatversion=2&plcontinue=37751%7C0%7CPainted_turtle&pllimit=max&plnamespace=0&prop=links&titles=Turtle

Variables

View Source
var IdToNameBucket = []byte("id-name")

Bucket names

View Source
var InLinksBucket = []byte("inlinks")
View Source
var NameToIdBucket = []byte("name-id")
View Source
var OutLinksBucket = []byte("outlinks")

Functions

func ReqLog

func ReqLog(Logger zerolog.Logger, w http.ResponseWriter, r *http.Request, s time.Time, msg string, level zerolog.Level)

Types

type AllLinksContinue

type AllLinksContinue struct {
	Gapcontinue string `json:"gapcontinue"`
	Continue    string `json:"continue"`
}

type AllLinksLimits

type AllLinksLimits struct {
	Allpages int `json:"allpages"`
}

type AllLinksPages

type AllLinksPages struct {
	Pageid int    `json:"pageid"`
	Ns     int    `json:"ns"`
	Title  string `json:"title"`
}

type AllLinksQuery

type AllLinksQuery struct {
	Pages []AllLinksPages `json:"pages"`
}

type AllLinksStruct

type AllLinksStruct struct {
	Batchcomplete bool             `json:"batchcomplete"`
	Continue      AllLinksContinue `json:"continue"`
	Limits        AllLinksLimits   `json:"limits"`
	Query         AllLinksQuery    `json:"query"`
}

type ApiHandler

type ApiHandler struct {
	DB     *DatabaseHandler
	Search *SearchHandler
	Router *chi.Mux
	Logger *LoggingHandler
}

func MakeApiHandler

func MakeApiHandler(db_path string, logLevel zerolog.Level, writer io.Writer) (*ApiHandler, error)

func (*ApiHandler) HealthRoute

func (a *ApiHandler) HealthRoute(w http.ResponseWriter, r *http.Request)

HealthRoute for health checking purposes

func (*ApiHandler) SearchRoute

func (a *ApiHandler) SearchRoute(w http.ResponseWriter, r *http.Request)

SearchRoute handles searching path between two articles

func (*ApiHandler) Serve

func (a *ApiHandler) Serve(addr string) error

type DatabaseHandler

type DatabaseHandler struct {
	DB     *bolt.DB
	Logger *log.Logger
}

func MakeDbHandler

func MakeDbHandler(path string) (*DatabaseHandler, error)
func (d *DatabaseHandler) AddLinks(src uint32, dst []uint32) error

AddLinks creates multiple connections in the database, in the incoming and outgoing buckets

func (*DatabaseHandler) Close

func (d *DatabaseHandler) Close()

func (*DatabaseHandler) CreateArticle

func (d *DatabaseHandler) CreateArticle(name string, id uint32) error

CreateArticle creates an article in the database, in id-name and name-id buckets

func (*DatabaseHandler) CreateBuckets

func (d *DatabaseHandler) CreateBuckets() error

CreateBuckets creates the 4 buckets

func (*DatabaseHandler) GetAllArticles

func (d *DatabaseHandler) GetAllArticles() (map[string]uint32, error)

GetAllArticles returns a map of all articles and their Id's

func (*DatabaseHandler) GetId

func (d *DatabaseHandler) GetId(name string) (uint32, error)

GetId returns article id by given name

func (*DatabaseHandler) GetIncoming

func (d *DatabaseHandler) GetIncoming(id uint32) ([]uint32, error)

GetOutgoing returns article ids by given destination id

func (*DatabaseHandler) GetName

func (d *DatabaseHandler) GetName(id uint32) (string, error)

GetName returns article name by given id

func (*DatabaseHandler) GetOutgoing

func (d *DatabaseHandler) GetOutgoing(id uint32) ([]uint32, error)

GetOutgoing returns article ids by given source id

func (*DatabaseHandler) IdsToNames

func (d *DatabaseHandler) IdsToNames(ids ...uint32) ([]string, error)

IdsToNames returns a list of names of given ids

type LinksToContinue

type LinksToContinue struct {
	Plcontinue string `json:"plcontinue"`
	Continue   string `json:"continue"`
}

type LinksToLimits

type LinksToLimits struct {
	Links int `json:"links"`
}
type LinksToLinks struct {
	Ns    int    `json:"ns"`
	Title string `json:"title"`
}

type LinksToPages

type LinksToPages struct {
	Pageid int            `json:"pageid"`
	Ns     int            `json:"ns"`
	Title  string         `json:"title"`
	Links  []LinksToLinks `json:"links"`
}

type LinksToQuery

type LinksToQuery struct {
	Pages []LinksToPages `json:"pages"`
}

type LinksToStruct

type LinksToStruct struct {
	Continue LinksToContinue `json:"continue"`
	Query    LinksToQuery    `json:"query"`
	Limits   LinksToLimits   `json:"limits"`
}

type LoggingHandler

type LoggingHandler struct {
	Logger  zerolog.Logger
	Session *session.Session
	Svc     *cloudwatchlogs.CloudWatchLogs
}

LoggingHandler logs to disk and cloudwatch

func MakeLoggingHandler

func MakeLoggingHandler(logLevel zerolog.Level, filewriter io.Writer) (*LoggingHandler, error)

func (*LoggingHandler) Write

func (log *LoggingHandler) Write(p []byte) (n int, err error)

type Node

type Node struct {
	Id     uint32
	Parent *Node
}

func (*Node) ToList

func (n *Node) ToList() []uint32

ToList converts a node to it's path

type ScrapeHandler

type ScrapeHandler struct {
	DB     *DatabaseHandler
	Client *http.Client
}

func MakeScrapeHandler

func MakeScrapeHandler(db *DatabaseHandler) *ScrapeHandler

func (*ScrapeHandler) GetAllArticles

func (s *ScrapeHandler) GetAllArticles(region string, callback func([]string)) error

GetAllArticles executes calllback on the titles of all articles in a given region

func (s *ScrapeHandler) GetAllLinks(region, title string, callback func([]string)) error

GetAllLinks executes callback on the list of links to a certain title in a region

type SearchHandler

type SearchHandler struct {
	DB *DatabaseHandler
}

func MakeSearchHandler

func MakeSearchHandler(db *DatabaseHandler) *SearchHandler

func (*SearchHandler) ShortestPath

func (s *SearchHandler) ShortestPath(src, dst uint32, hopEvent func(int)) ([]uint32, error)

ShortestPath finds the shortest path in the database between src and dst, execute hopEvent at every hop

type SearchResult

type SearchResult struct {
	Error        string   `json:"error,omitempty"`
	ResultIds    []uint32 `json:"ids,omitempty"`
	ResultTitles []string `json:"titles,omitempty"`
}

Jump to

Keyboard shortcuts

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