frontend

package
v0.0.0-...-c5d5a31 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2020 License: Apache-2.0 Imports: 47 Imported by: 1

Documentation

Overview

Package frontend provides the routing and middleware for the web app

Index

Constants

This section is empty.

Variables

View Source
var ParseTemplates = func() {
	templates = make(map[string]*template.Template)
	templates["about"] = template.Must(
		template.New("base.html").
			Funcs(funcMap).
			ParseFiles(
				"templates/base.html",
				"templates/search_form.html",
				"templates/about.html",
			),
	)

	var err error
	t := template.New("tmp")
	t, err = t.Parse(`{{template "answer" .}}`)
	if err != nil {
		panic(err)
	}

	templates["answer"] = template.Must(
		t.Funcs(funcMap).
			ParseFiles(
				"templates/wikipedia.html",
				"templates/answer.html",
			),
	)
	templates["maps"] = template.Must(
		template.New("maps.html").
			Funcs(funcMap).
			ParseFiles(
				"templates/maps.html",
			),
	)
	templates["opensearch"] = template.Must(
		template.New("opensearch.xml").
			ParseFiles(
				"templates/opensearch.xml",
			),
	)
	templates["proxy_header"] = template.Must(
		template.New("base.html").
			Funcs(funcMap).
			ParseFiles(
				"templates/base.html",
				"templates/search_form.html",
				"templates/proxy_header.html",
			),
	)
	templates["proxy"] = template.Must(
		template.New("base.html").
			Funcs(funcMap).
			ParseFiles(
				"templates/base.html",
				"templates/search_form.html",
				"templates/proxy.html",
			),
	)
	templates["search"] = template.Must(
		template.New("base.html").
			Funcs(funcMap).
			ParseFiles(
				"templates/base.html",
				"templates/answer.html",
				"templates/search_form.html",
				"templates/search.html",
				"templates/wikipedia.html",
			),
	)
}

ParseTemplates parses our html templates.

Functions

This section is empty.

Types

type AnswerResponse

type AnswerResponse struct {
	HTML       string   `json:"html"`
	CSS        []string `json:"css"`
	JavaScript []string `json:"javascript"`
}

AnswerResponse is an instant answer response

type Brand

type Brand struct {
	Name      string
	Host      string
	TagLine   string
}

Brand allows for customization of the name and tagline

type Context

type Context struct {
	Q string        `json:"query"`
	L string        `json:"-"`
	D string        `json:"-"`
	F search.Filter `json:"-"`

	POST         bool            `json:"-"`
	R            string          `json:"-"`
	S            string          `json:"-"`
	N            string          `json:"-"`
	T            string          `json:"-"`
	Ref          string          `json:"-"`
	Safe         bool            `json:"-"`
	DefaultBangs []DefaultBang   `json:"-"`
	Preferred    []language.Tag  `json:"-"`
	Region       language.Region `json:"-"`
	Number       int             `json:"-"`
	Page         int             `json:"-"`
	Theme        string          `json:"-"`
	// contains filtered or unexported fields
}

Context holds a user's request context so we can pass it to our template's form. Query, Language, and Region are the RAW query string variables.

type DefaultBang

type DefaultBang struct {
	Trigger string
	bangs.Bang
}

DefaultBang is the user's preffered !bang

type Document

type Document struct {
	Languages []language.Tag
	language.Matcher
}

Document has the languages we support

type Frontend

type Frontend struct {
	Brand
	Document
	*bangs.Bangs
	Cache struct {
		cache.Cacher
		Instant time.Duration
		Search  time.Duration
	}
	Images struct {
		img.Fetcher
		*http.Client
	}
	*instant.Instant
	MapBoxKey   string
	Onion       string
	ProxyClient *http.Client
	Suggest     suggest.Suggester
	Search      search.Fetcher
	Wikipedia
	GitHub
}

Frontend holds settings for branding, cache, search backend, etc.

func (*Frontend) DetectInstantAnswer

func (f *Frontend) DetectInstantAnswer(r *http.Request, lang language.Tag, onlyMaps bool) instant.Data

DetectInstantAnswer triggers the instant answers

func (*Frontend) Router

func (f *Frontend) Router(cfg config.Provider) *mux.Router

Router sets up the routes & handlers

type GitHub

type GitHub struct {
	HTTPClient *http.Client
}

GitHub holds settings for GitHub's API

type Instant

type Instant struct {
	instant.Data
}

Instant is a wrapper to facilitate custom unmarshalling

func (*Instant) UnmarshalJSON

func (d *Instant) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals an instant answer to the correct data structure

type Results

type Results struct {
	Alternative string          `json:"-"`
	Images      *img.Results    `json:"images,omitempty"`
	Instant     instant.Data    `json:"-"`
	Search      *search.Results `json:"search,omitempty"`
}

Results is the results from search, instant, wikipedia, etc

type Wikipedia

type Wikipedia struct {
	language.Matcher
}

Wikipedia holds our settings for wikipedia/wikidata Note: language matcher here may be different than that for document due to available languages Wikipedia supports

Directories

Path Synopsis
Package cache provides simple caching mechanisms
Package cache provides simple caching mechanisms
Command frontend demonstrates how to run the web app
Command frontend demonstrates how to run the web app

Jump to

Keyboard shortcuts

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