middleware

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIKeyHeader

func APIKeyHeader(header string, allow AuthFunc) func(http.Handler) http.Handler

APIKeyHeader requires a valid API key in a header.

func APIKeyQuery

func APIKeyQuery(name string, allow AuthFunc) func(http.Handler) http.Handler

APIKeyQuery requires a valid API key in a query parameter.

func BearerToken

func BearerToken(allow AuthFunc) func(http.Handler) http.Handler

BearerToken requires a valid Authorization: Bearer token.

func BodyLimit

func BodyLimit(limit int64) func(http.Handler) http.Handler

BodyLimit caps the size of incoming request bodies.

func CORS

func CORS(config CORSConfig) func(http.Handler) http.Handler

CORS adds a small dependency-free CORS middleware.

func Recover

func Recover() func(http.Handler) http.Handler

Recover converts panics into RFC 9457 Problem Details responses.

func RequestID

func RequestID() func(http.Handler) http.Handler

RequestID ensures each request has an X-Request-ID header and context value.

func RequestIDFromContext

func RequestIDFromContext(ctx context.Context) string

RequestIDFromContext returns the request ID set by RequestID.

func SecureHeaders

func SecureHeaders() func(http.Handler) http.Handler

SecureHeaders adds conservative browser security headers.

func Timeout

func Timeout(duration time.Duration) func(http.Handler) http.Handler

Timeout limits the time a handler may spend serving a request.

Types

type AuthFunc

type AuthFunc func(string) bool

type CORSConfig

type CORSConfig struct {
	AllowedOrigins []string
	AllowedMethods []string
	AllowedHeaders []string
}

Jump to

Keyboard shortcuts

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