httpserver

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package httpserver contains the shared Gin HTTP server used by both the desktop (main) and mobile entry points. Callers configure behaviour via Options and get back a *gin.Engine ready to be Run on any net.Listener.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MddFileHandler

func MddFileHandler(c *gin.Context)

MddFileHandler serves a single MDD resource (audio/image) on demand. Register it as NoRoute to handle <img src="/..."> and <audio src="/...">.

func New

func New(opts Options) *gin.Engine

New builds and returns a configured *gin.Engine.

func PageTitle

func PageTitle(query string) string

PageTitle formats the browser tab title.

func QueryDefinition

func QueryDefinition(word string) string

QueryDefinition is exported so main.go can call it for the CLI one-shot mode.

func SafeNext

func SafeNext(next string) string

SafeNext validates a redirect target is a local path.

Types

type DefinitionMatchView

type DefinitionMatchView struct {
	Word        string
	Src         string
	SnippetHTML template.HTML
}

DefinitionMatchView is a single definition search result for the template.

type Options

type Options struct {
	// History is used to record queries. May be nil (disables recording).
	History *history.History

	// EnableAuth adds /login, /auth, and /review routes with session middleware.
	EnableAuth bool

	// AuthSetup is called after the gin.Engine is created so the caller can
	// attach session middleware and auth route handlers. Only called when
	// EnableAuth is true.
	AuthSetup func(r *gin.Engine)

	// Middleware is applied globally before any routes are registered.
	Middleware []gin.HandlerFunc

	// ResourceHandler is registered as NoRoute to serve static assets
	// (audio, images) on unmatched paths. If nil, no NoRoute is registered
	// and the caller is responsible for serving assets (e.g. via static middleware).
	ResourceHandler gin.HandlerFunc
}

Options configures the HTTP server.

type PageData

type PageData struct {
	Title      string
	Query      string
	Engine     string
	SearchMode string
	Error      string
	EntryHTML  template.HTML
	Results    []DefinitionMatchView
	Words      []wordbank.Word
	InWordBank bool
}

PageData is the template context shared across all HTML pages.

Jump to

Keyboard shortcuts

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