middleware

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Auth

func Auth(validator AuthValidator) func(http.Handler) http.Handler

Auth returns middleware that enforces authentication on all non-exempt paths. When auth is nil (auth disabled), the middleware is a no-op pass-through.

func CORS

func CORS(next http.Handler) http.Handler

CORS middleware adds Cross-Origin Resource Sharing headers. Uses the request Origin so it works for both localhost development and remote access (the client and server share the same origin in production).

func CORSWithOrigins

func CORSWithOrigins(allowedOrigins []string) func(http.Handler) http.Handler

CORSWithOrigins creates CORS middleware with specific allowed origins. Use this in production with your actual domain.

func Compress

func Compress(next http.Handler) http.Handler

Compress adds transparent response compression for clients that advertise support via Accept-Encoding. zstd is preferred over gzip for better compression ratios. WebSocket upgrade requests are passed through unmodified. For long-lived streaming responses, the compression buffer is flushed on every Flush() call so clients receive frames in real time.

func Logging

func Logging(next http.Handler) http.Handler

Logging middleware logs all HTTP requests with timing information.

func LoggingWithDetails

func LoggingWithDetails(next http.Handler) http.Handler

LoggingWithDetails provides more detailed logging including query params and headers.

func StaticFileServer

func StaticFileServer(fileSystem fs.FS, indexFile string) http.Handler

StaticFileServer creates an HTTP handler that serves static files from an embedded filesystem. It implements SPA (Single Page Application) routing by serving index.html for non-file routes.

Types

type AuthValidator

type AuthValidator interface {
	ValidateAuthSession(token string) bool
}

AuthValidator is the minimal interface the auth middleware needs from the session manager.

Jump to

Keyboard shortcuts

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