Documentation
¶
Overview ¶
Package middlewares exposes the Gothic runtime as a single chi middleware, driven by the Runtime block declared in gothic.config.go. Applied like any chi middleware (router.Use), it keeps main.go tiny while new built-in route features light up automatically on a framework upgrade — the user never edits main.go.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Logger ¶
func Logger(cfg ...LoggingConfig) func(http.Handler) http.Handler
Logger returns a chi-compatible HTTP middleware that logs every request.
The config argument is optional: Logger() takes every setting from the environment, and Logger(LoggingConfig{Verbose: true}) pins verbosity in code.
In dev mode (GOTHIC_MODE=dev) with no verbose flag the middleware is a no-op passthrough. Log format is selected by GOTHIC_PROVIDER: "AWS" produces JSON for a log collector. Otherwise the output is a coloured request line on an interactive terminal, and plain key=value text whenever the stream is redirected. The LoggingConfig.Verbose field and GOTHIC_VERBOSE env var both control verbosity — if either is true, verbose logging is on.
func Middleware ¶
Middleware returns a chi middleware — applied like router.Use(middlewares.Logger(...)) — that wires the whole Gothic runtime from a single RuntimeConfig: it initializes the cache backend once, then serves the framework's built-in paths (/public/* static assets and the /optimizedImage/* endpoint), letting every other request fall through to the routes you register on the router. New built-in route features are added here and appear automatically.
func SetEmbeddedPublicFS ¶ added in v1.2.0
SetEmbeddedPublicFS registers the embed.FS backing /public/* when the app's RuntimeConfig uses ServeStaticFiles == EMBEDDED. It forwards into the core router. The generated root embed file (which owns the //go:embed public directive) calls this from init(), before main(); user main.go imports this package, not core/router directly. fsys MUST already be rooted at the public dir (fs.Sub'd).
Types ¶
type LoggingConfig ¶
type LoggingConfig struct {
// Verbose enables per-request logging even in dev mode.
// May also be enabled via the GOTHIC_VERBOSE env var.
Verbose bool
}
LoggingConfig controls the behavior of the Logger middleware.