handler

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2024 License: GPL-3.0 Imports: 36 Imported by: 0

Documentation

Overview

Package handler provides the HTTP handlers for the Defacto2 website. Using the Echo web framework, the handler is the entry point for the web server.

Index

Constants

View Source
const (
	// ShutdownCounter is the number of iterations to wait before shutting down the server.
	ShutdownCounter = 3

	// ShutdownWait is the number of seconds to wait before shutting down the server.
	ShutdownWait = ShutdownCounter * time.Second

	// Downloader is the route for the file download handler.
	Downloader = "/d/:id"
)

Variables

View Source
var (
	ErrFS      = errors.New("embed filesystem instance is empty")
	ErrName    = errors.New("name is empty")
	ErrName404 = errors.New("named template cannot be found")
	ErrPorts   = errors.New("the server ports are not configured")
	ErrRoutes  = errors.New("echo instance is nil")
	ErrZap     = errors.New("zap logger instance is nil")
)

Functions

func EmbedDirs

func EmbedDirs(e *echo.Echo, currentFs fs.FS) *echo.Echo

EmbedDirs serves the static files from the directories embed to the binary.

func MovedPermanently

func MovedPermanently(e *echo.Echo) *echo.Echo

MovedPermanently redirects are partial URL routers that are to be redirected with a HTTP 301 Moved Permanently.

Types

type Configuration

type Configuration struct {
	Public      embed.FS      // Public facing files.
	View        embed.FS      // View contains Go templates.
	Version     string        // Version is the results of GoReleaser build command.
	Brand       []byte        // Brand contains the Defacto2 ASCII logo.
	Environment config.Config // Environment configurations from the host system.
	RecordCount int           // The total number of file records in the database.
}

Configuration of the handler.

func (Configuration) Controller

func (c Configuration) Controller(db *sql.DB, logger *zap.SugaredLogger) *echo.Echo

Controller is the primary instance of the Echo router.

func (Configuration) FilesRoutes

func (c Configuration) FilesRoutes(e *echo.Echo, db *sql.DB, logger *zap.SugaredLogger,
	public embed.FS,
) (*echo.Echo, error)

FilesRoutes defines the file locations and routes for the web server.

func (Configuration) Info

func (c Configuration) Info(logger *zap.SugaredLogger, w io.Writer)

Info prints the application information to the console.

func (Configuration) NoCrawl

func (c Configuration) NoCrawl(next echo.HandlerFunc) echo.HandlerFunc

NoCrawl middleware adds a `X-Robots-Tag` header to the response. The header contains the noindex and nofollow values that tell search engine crawlers to not index or crawl the page or asset. See https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag#xrobotstag

func (Configuration) PortErr

func (c Configuration) PortErr(logger *zap.SugaredLogger, port uint, err error)

PortErr handles the error when the HTTP or HTTPS server cannot start.

func (Configuration) ReadOnlyLock

func (c Configuration) ReadOnlyLock(next echo.HandlerFunc) echo.HandlerFunc

ReadOnlyLock disables all PATCH, POST, PUT and DELETE requests for the modification of the database and any related user interface.

func (Configuration) Registry

func (c Configuration) Registry(db *sql.DB, logger *zap.SugaredLogger) (*TemplateRegistry, error)

Registry returns the template renderer.

func (Configuration) SessionLock

func (c Configuration) SessionLock(next echo.HandlerFunc) echo.HandlerFunc

SessionLock middleware checks the session cookie for a valid signed in client.

func (*Configuration) ShutdownHTTP

func (c *Configuration) ShutdownHTTP(e *echo.Echo, logger *zap.SugaredLogger)

ShutdownHTTP waits for a Ctrl-C keyboard press to initiate a graceful shutdown of the HTTP web server. The shutdown procedure occurs a few seconds after the key press.

func (*Configuration) Start

func (c *Configuration) Start(e *echo.Echo, logger *zap.SugaredLogger, configs config.Config) error

Start the HTTP, and-or the TLS servers.

func (*Configuration) StartHTTP

func (c *Configuration) StartHTTP(e *echo.Echo, logger *zap.SugaredLogger)

StartHTTP starts the insecure HTTP web server.

func (*Configuration) StartTLS

func (c *Configuration) StartTLS(e *echo.Echo, logger *zap.SugaredLogger)

StartTLS starts the encrypted TLS web server.

func (*Configuration) StartTLSLocal

func (c *Configuration) StartTLSLocal(e *echo.Echo, logger *zap.SugaredLogger)

StartTLSLocal starts the localhost, encrypted TLS web server. This should only be triggered when the server is running in local mode.

type TemplateRegistry

type TemplateRegistry struct {
	Templates map[string]*template.Template
}

TemplateRegistry is template registry struct.

func (*TemplateRegistry) Render

func (t *TemplateRegistry) Render(w io.Writer, name string, data interface{}, c echo.Context) error

Render the layout template with the core HTML, META and BODY elements.

Directories

Path Synopsis
app
Package app handles the routes and views for the Defacto2 website.
Package app handles the routes and views for the Defacto2 website.
internal/extensions
Package extensions provides a list of file extensions used by some functions in app.
Package extensions provides a list of file extensions used by some functions in app.
internal/filerecord
Package filerecord provides functions for the file model which is an artifact record.
Package filerecord provides functions for the file model which is an artifact record.
internal/fileslice
Package fileslice provides functions that return model FileSlices, which are multiple artifact records.
Package fileslice provides functions that return model FileSlices, which are multiple artifact records.
internal/simple
Package simple provides functions for handling string or integer input data.
Package simple provides functions for handling string or integer input data.
remote
Package remote provides the remote download and update of artifact data from third-party sources such as API's.
Package remote provides the remote download and update of artifact data from third-party sources such as API's.
Package cache provides a lightweight engine for storing key/value pairs.
Package cache provides a lightweight engine for storing key/value pairs.
Package demozoo handles the retrieval of [production records] from the [Demozoo] API and the extraction of relevant data for the Defacto2 website.
Package demozoo handles the retrieval of [production records] from the [Demozoo] API and the extraction of relevant data for the Defacto2 website.
Package download handles the client file downloads.
Package download handles the client file downloads.
Package form provides functions for providing data for form and input elements.
Package form provides functions for providing data for form and input elements.
Package html3 renders the html3 sub-route of the website.
Package html3 renders the html3 sub-route of the website.
ext
Package ext contains common filename extensions used by the file records.
Package ext contains common filename extensions used by the file records.
Package htmx handles the routes and views for the AJAX responses using the htmx library.
Package htmx handles the routes and views for the AJAX responses using the htmx library.
Package jsdos configures the js-dos v6.22 emulator.
Package jsdos configures the js-dos v6.22 emulator.
msdos
Package msdos provides functions for working with MS-DOS FAT 12/16 file system filenames.
Package msdos provides functions for working with MS-DOS FAT 12/16 file system filenames.
Package pouet provides production, user voting data sourced from the Pouet website API.
Package pouet provides production, user voting data sourced from the Pouet website API.
Package readme provides functions for reading and suggesting readme files.
Package readme provides functions for reading and suggesting readme files.
Package render provides the file content rendering for the web server.
Package render provides the file content rendering for the web server.
Package sess provides functions for handling session and cookies.
Package sess provides functions for handling session and cookies.
Package web proves links and titles for recommended websites.
Package web proves links and titles for recommended websites.
Package sixteen provides data about releasers and groups on the 16colors website.
Package sixteen provides data about releasers and groups on the 16colors website.

Jump to

Keyboard shortcuts

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