Documentation
¶
Index ¶
- Constants
- Variables
- func ReqLog(Logger zerolog.Logger, w http.ResponseWriter, r *http.Request, s time.Time, ...)
- type AllLinksContinue
- type AllLinksLimits
- type AllLinksPages
- type AllLinksQuery
- type AllLinksStruct
- type ApiHandler
- type DatabaseHandler
- func (d *DatabaseHandler) AddLinks(src uint32, dst []uint32) error
- func (d *DatabaseHandler) Close()
- func (d *DatabaseHandler) CreateArticle(name string, id uint32) error
- func (d *DatabaseHandler) CreateBuckets() error
- func (d *DatabaseHandler) GetAllArticles() (map[string]uint32, error)
- func (d *DatabaseHandler) GetId(name string) (uint32, error)
- func (d *DatabaseHandler) GetIncoming(id uint32) ([]uint32, error)
- func (d *DatabaseHandler) GetName(id uint32) (string, error)
- func (d *DatabaseHandler) GetOutgoing(id uint32) ([]uint32, error)
- func (d *DatabaseHandler) IdsToNames(ids ...uint32) ([]string, error)
- type LinksToContinue
- type LinksToLimits
- type LinksToLinks
- type LinksToPages
- type LinksToQuery
- type LinksToStruct
- type LoggingHandler
- type Node
- type ScrapeHandler
- type SearchHandler
- type SearchResult
Constants ¶
const AllLinksTemplate = `` /* 150-byte string literal not displayed */
const LinksToTemplate = `https://%s.wikipedia.org/w/api.php?action=query&format=json&formatversion=2&pllimit=max&plnamespace=0&prop=links&titles=%s`
Variables ¶
var IdToNameBucket = []byte("id-name")
Bucket names
var InLinksBucket = []byte("inlinks")
var NameToIdBucket = []byte("name-id")
var OutLinksBucket = []byte("outlinks")
Functions ¶
Types ¶
type AllLinksContinue ¶
type AllLinksLimits ¶
type AllLinksLimits struct {
Allpages int `json:"allpages"`
}
type AllLinksPages ¶
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 (*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 ¶
func MakeDbHandler ¶
func MakeDbHandler(path string) (*DatabaseHandler, error)
func (*DatabaseHandler) AddLinks ¶
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 LinksToLimits ¶
type LinksToLimits struct {
Links int `json:"links"`
}
type LinksToLinks ¶
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 ¶
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 (*ScrapeHandler) GetAllLinks ¶
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