middlewares

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 8 Imported by: 0

README

Gothic Framework — Middlewares

The Gothic runtime as a single chi middleware for Gothic Framework apps.

github.com/gothicframework/middlewares

Add it to a Gothic project:

go get github.com/gothicframework/middlewares

This module builds on the core runtime (github.com/gothicframework/core) and the component catalogue (github.com/gothicframework/components). It exposes a single member, middlewares.Middleware.


middlewares.Middleware

import "github.com/gothicframework/middlewares"
Middleware(cfg config.RuntimeConfig) func(http.Handler) http.Handler

Returns a chi middleware — applied like router.Use(...) — that wires the entire Gothic runtime from the single Runtime block in gothic.config.go:

  • initializes the process-wide cache backend once (per RuntimeConfig);
  • serves the framework's built-in paths — /public/* static assets, the /optimizedImage/* endpoint (with full chi routing for its URL params), and the WASM-runtime assets under /_gothic/* served from the framework embed; and
  • lets every other request fall through to the file-based routes you register on the main router.

New built-in route features are added here and light up automatically on a framework upgrade — you never edit main.go.

router := chi.NewMux()
router.Use(middlewares.Middleware(Config.Runtime)) // whole Gothic runtime
routes.RegisterFileBasedRoutes(router)             // your file-based pages

The built-in routes run on their own internal chi mux (so OptimizedImage keeps its chi.URLParam access); only /public/*, /optimizedImage/*, and /_gothic/* are handled there — everything else passes through to next.


Requirements

  • Gothic core github.com/gothicframework/core — provides config.RuntimeConfig, the router setup, and runtimeassets.
  • Gothic components github.com/gothicframework/components — provides the OptimizedImage route registration.
  • Go 1.25+ and go-chi/chi/v5.

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 Middleware

func Middleware(cfg config.RuntimeConfig) func(http.Handler) http.Handler

Middleware returns a chi middleware — applied like router.Use(middleware.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

func SetEmbeddedPublicFS(fsys fs.FS)

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

This section is empty.

Jump to

Keyboard shortcuts

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