wikilinkui

package module
v0.0.0-...-88ed6e6 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: 19 Imported by: 0

README

WikiLinkUI

This is a repository for the web UI for the WikiLinkAPI

Running

To run the UI run go run ./cmd/wikilinkui:

NAME:
   wikilinkui - Serves the WikiLink web ui

USAGE:
   wikilinkui [global options] command [command options] [arguments...]

COMMANDS:
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --config_path value, -c value  Path to config file (default: "/var/wikilinkui/.env")
   --help, -h                     show help

Config

The .env configuration file should have the following format:

UI_PORT="3000"
API_ADDR="localhost:2048"
REDIS_ADDR="localhost:6379"
LOG_LEVEL="info"
LOG_PATH="wikilinkui.log"

Documentation

Index

Constants

View Source
const WikiRandomEndpoint = `https://he.wikipedia.org/w/api.php?action=query&generator=random&grnnamespace=0&grnlimit=8&utf8=&format=json`
View Source
const WikiSearchEndpoint = `https://he.wikipedia.org/w/api.php?action=query&list=search&srnamespace=0&srlimit=8&utf8=&format=json&srsearch=`

Variables

This section is empty.

Functions

func ReqLog

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

Types

type DestStruct

type DestStruct struct {
	SrcFinal string
	Error    string
	Result   []string
}

type FinalStruct

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

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 RandomContinue

type RandomContinue struct {
	Grncontinue string `json:"grncontinue"`
	Continue    string `json:"continue"`
}

type RandomPage

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

type RandomQuery

type RandomQuery struct {
	Pages map[string]RandomPage `json:"pages"`
}

type RandomResult

type RandomResult struct {
	Batchcomplete string         `json:"batchcomplete"`
	Continue      RandomContinue `json:"continue"`
	Query         RandomQuery    `json:"query"`
}

Random results from wikipedia

type RedisHandler

type RedisHandler struct {
	RedisAddress string
	VaultAddress string
	VaultRole    string
	VaultClient  *vault.Client
	RedisClient  *redis.Client
	RedisTTL     time.Time
	Logger       *LoggingHandler
}

func MakeRedisHandler

func MakeRedisHandler(rAddr, vAddr, vRole string, logger *LoggingHandler) (*RedisHandler, error)

func (*RedisHandler) GetValue

func (r *RedisHandler) GetValue(key string) (string, error)

func (*RedisHandler) PutValue

func (r *RedisHandler) PutValue(key, value string) error
type Search struct {
	Ns        int       `json:"ns"`
	Title     string    `json:"title"`
	Pageid    int       `json:"pageid"`
	Size      int       `json:"size"`
	Wordcount int       `json:"wordcount"`
	Snippet   string    `json:"snippet"`
	Timestamp time.Time `json:"timestamp"`
}

type SearchContinue

type SearchContinue struct {
	Sroffset int    `json:"sroffset"`
	Continue string `json:"continue"`
}

type SearchInfo

type SearchInfo struct {
	Totalhits int `json:"totalhits"`
}

type SearchQuery

type SearchQuery struct {
	SearchInfo SearchInfo `json:"searchinfo"`
	Search     []Search   `json:"search"`
}

type SearchResult

type SearchResult struct {
	Batchcomplete string         `json:"batchcomplete"`
	Continue      SearchContinue `json:"continue"`
	Query         SearchQuery    `json:"query"`
}

Search Result from Wikipedia

type SourceStruct

type SourceStruct struct {
	Error  string
	Result []string
}

type UIHandler

type UIHandler struct {
	Locale    string
	LinkAPI   string
	Redis     *RedisHandler
	Client    *http.Client
	Router    *chi.Mux
	Templates map[string]*template.Template
	Logger    *LoggingHandler
}

func MakeUIHandler

func MakeUIHandler(locale, apiAddr, rAddr, vAddr, vRole string, logLevel zerolog.Level, writer io.Writer) (*UIHandler, error)

("heb", apiAddr, rAddr, rRole, vAddr, vRegion, vRole, level, logf)

func (*UIHandler) DestRoute

func (h *UIHandler) DestRoute(w http.ResponseWriter, r *http.Request)

func (*UIHandler) FinalRoute

func (h *UIHandler) FinalRoute(w http.ResponseWriter, r *http.Request)

FinalRoute searches the path between two articles

func (*UIHandler) HealthRoute

func (u *UIHandler) HealthRoute(w http.ResponseWriter, r *http.Request)

HealthRoute for health checking purposes

func (*UIHandler) Path

func (h *UIHandler) Path(src, dst string) (*FinalStruct, error)

Path searches LinkAPI for a path between articles consults the redis cache for quick retrieval

func (*UIHandler) Random

func (h *UIHandler) Random() ([]string, error)

Random gets random articles from wikipedia does not consult cache

func (*UIHandler) Search

func (h *UIHandler) Search(query string) ([]string, error)

Search searches wikipedia for articles consults the redis cache for quick retrieval

func (*UIHandler) Serve

func (u *UIHandler) Serve(addr string) error

func (*UIHandler) SourceRoute

func (h *UIHandler) SourceRoute(w http.ResponseWriter, r *http.Request)

SourceRoute is the index of the applicatoin

Directories

Path Synopsis
cmd
wikilinkui command

Jump to

Keyboard shortcuts

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