middleware

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package middleware provides HTTP middleware for the server (auth, COP, security headers, logging).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthMiddleware

func AuthMiddleware(store *sessions.CookieStore, sessionManager session.SessionManager, config *AuthConfig) func(http.Handler) http.Handler

AuthMiddleware creates a middleware that protects routes by checking for a valid session. If the user is not authenticated, it returns 401 Unauthorized. It accepts a session store for checking authentication and a session manager for clearing sessions.

func ConditionalMiddleware

func ConditionalMiddleware(next http.Handler) http.Handler

ConditionalMiddleware handles If-None-Match and If-Modified-Since requests Returns 304 Not Modified if validators match, otherwise calls the next handler This middleware must be placed AFTER handlers that set validators (ETag, Last-Modified) For now, we'll let handlers execute and then check validators in a wrapper

func NewLoggingMiddleware

func NewLoggingMiddleware(logger *slog.Logger) func(http.Handler) http.Handler

NewLoggingMiddleware creates a logging middleware function that accepts a logger. If logger is nil, it uses the default slog logger.

func PprofAccess added in v0.16.0

func PprofAccess(next http.Handler) http.Handler

PprofAccess gates Go pprof HTTP endpoints. Proxied requests and non-loopback direct requests receive 404 before inner handlers run. Direct loopback requests reach next (typically authMiddleware + pprof handler).

func SecurityHeaders added in v0.16.0

func SecurityHeaders(next http.Handler) http.Handler

SecurityHeaders sets baseline response headers on every response: nosniff and a minimal CSP that blocks cross-origin framing (clickjacking).

Types

type AuthConfig

type AuthConfig struct {
	// DebugDelayMS is an optional debug delay in milliseconds to add to requests.
	// If IsSet is false or value is 0, no delay is added.
	DebugDelayMS struct {
		IsSet bool
		Int   int
	}
}

AuthConfig holds configuration for auth middleware behavior.

Jump to

Keyboard shortcuts

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