middleware

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CORS

func CORS(cfg CORSConfig) bast.MiddlewareFunc

CORS returns a middleware that applies Cross-Origin Resource Sharing headers. Panics on AllowedOrigins ["*"] combined with AllowCredentials: the Fetch spec forbids the pair and every browser rejects it, so it is always a config bug.

func Logger

func Logger(next bast.HandlerFunc) bast.HandlerFunc

Logger logs method, path, status code, duration, and client IP for every request.

func Recover

func Recover(next bast.HandlerFunc) bast.HandlerFunc

Recover catches panics in downstream handlers, logs them, and returns a 500. Framework code must not panic — this catches user handler panics only.

func RequestID

func RequestID(next bast.HandlerFunc) bast.HandlerFunc

RequestID generates a unique request ID, stores it in the Ctx, and attaches it as X-Request-ID on the response.

Types

type CORSConfig

type CORSConfig struct {
	AllowedOrigins   []string // Use ["*"] to allow all origins.
	AllowedMethods   []string // Defaults to GET, POST, PUT, PATCH, DELETE, OPTIONS.
	AllowedHeaders   []string // Defaults to Content-Type, Authorization.
	ExposedHeaders   []string
	AllowCredentials bool
	MaxAge           int // Preflight cache duration in seconds.
}

CORSConfig configures the CORS middleware.

Jump to

Keyboard shortcuts

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