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
- Variables
- func EmbedDirs(e *echo.Echo, currentFs fs.FS) *echo.Echo
- func MovedPermanently(e *echo.Echo) *echo.Echo
- type Configuration
- func (c Configuration) Controller(logger *zap.SugaredLogger) *echo.Echo
- func (c Configuration) FilesRoutes(e *echo.Echo, logger *zap.SugaredLogger, public embed.FS) (*echo.Echo, error)
- func (c Configuration) Info(logger *zap.SugaredLogger, w io.Writer)
- func (c Configuration) NoCrawl(next echo.HandlerFunc) echo.HandlerFunc
- func (c Configuration) PortErr(logger *zap.SugaredLogger, port uint, err error)
- func (c Configuration) ReadOnlyLock(next echo.HandlerFunc) echo.HandlerFunc
- func (c Configuration) Registry(logger *zap.SugaredLogger) (*TemplateRegistry, error)
- func (c Configuration) SessionLock(next echo.HandlerFunc) echo.HandlerFunc
- func (c *Configuration) ShutdownHTTP(e *echo.Echo, logger *zap.SugaredLogger)
- func (c *Configuration) Start(e *echo.Echo, logger *zap.SugaredLogger, configs config.Config) error
- func (c *Configuration) StartHTTP(e *echo.Echo, logger *zap.SugaredLogger)
- func (c *Configuration) StartTLS(e *echo.Echo, logger *zap.SugaredLogger)
- func (c *Configuration) StartTLSLocal(e *echo.Echo, logger *zap.SugaredLogger)
- type TemplateRegistry
Constants ¶
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 ¶
var ( ErrCtx = errors.New("echo context is nil") ErrData = errors.New("data interface is nil") ErrFS = errors.New("embed filesystem instance is empty") ErrName = errors.New("template name string is empty") ErrPorts = errors.New("the server ports are not configured") ErrRoutes = errors.New("e echo instance is nil") ErrTmpl = errors.New("named template cannot be found") ErrW = errors.New("w io.writer instance is nil") ErrZap = errors.New("zap logger instance is nil") )
Functions ¶
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 { Environment config.Config // Environment configurations from the host system. Brand []byte // Brand contains the Defacto2 ASCII logo. Public embed.FS // Public facing files. View embed.FS // View contains Go templates. Version string // Version is the results of GoReleaser build command. RecordCount int // The total number of file records in the database. }
Configuration of the handler.
func (Configuration) Controller ¶
func (c Configuration) Controller(logger *zap.SugaredLogger) *echo.Echo
Controller is the primary instance of the Echo router.
func (Configuration) FilesRoutes ¶
func (c Configuration) FilesRoutes(e *echo.Echo, 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 POST, PUT and DELETE requests for the modification of the database and any related user interface.
func (Configuration) Registry ¶
func (c Configuration) Registry(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 ¶
TemplateRegistry is template registry struct.
Directories ¶
Path | Synopsis |
---|---|
Package app handles the routes and views for the Defacto2 website.
|
Package app handles the routes and views for the Defacto2 website. |
Package download handles the client file downloads.
|
Package download handles the client file downloads. |
Package html3 renders the html3 sub-route of the website.
|
Package html3 renders the html3 sub-route of the website. |
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 sess provides a function to check if a user is signed in and is an editor.
|
Package sess provides a function to check if a user is signed in and is an editor. |