middleware

package module
v0.0.0-...-a90ffd8 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2025 License: MIT Imports: 5 Imported by: 0

README

middleware

A collection of useful middlewares for any stdlib-compliant HTTP mux, namely chi.

Credits

The Recoverer, RequestID, RequestLogger and Logger middlewares were originally written by Zikaeroh for HortBot.

LICENSE

MIT

Documentation

Overview

Package middleware implements useful HTTP middleware for routers compatible with the standard library mux.

Index

Constants

View Source
const RequestIDHeader = "X-Request-ID"

RequestIDHeader is the key used for request IDs.

Variables

This section is empty.

Functions

func CORS

func CORS(origin string) func(http.Handler) http.Handler

CORS allows cross-site requests for the given origin.

func Logger

func Logger(l *slog.Logger) func(http.Handler) http.Handler

Logger adds the given *slog.Logger to a request's context.Context.

func Recoverer

func Recoverer(next http.Handler, fn http.HandlerFunc) http.Handler

Recoverer recovers from any panics in the request chain, logs the recover value and executes the given response handler.

func RequestID

func RequestID(next http.Handler) http.Handler

RequestID adds a unique identifier to each request.

func RequestLogger

func RequestLogger(next http.Handler) http.Handler

RequestLogger logs any incoming requests to the debug level if a *slog.Logger is present in the request's context.Context.

func RequestSize

func RequestSize(bytes int64) func(http.Handler) http.Handler

RequestSize limits the size a request's body may be.

Types

This section is empty.

Jump to

Keyboard shortcuts

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