middleware

package
v0.0.0-...-557cf9c Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2025 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package middleware implements a simple middleware pattern for http handlers, along with implementations for some common middlewares.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Middleware

type Middleware func(http.Handler) http.Handler

A Middleware is a func that wraps an http.Handler.

func Chain

func Chain(middlewares ...Middleware) Middleware

Chain creates a new Middleware that applies a sequence of Middlewares, so that they execute in the given order when handling an http request.

In other words, Chain(m1, m2)(handler) = m1(m2(handler))

A similar pattern is used in e.g. github.com/justinas/alice: https://github.com/justinas/alice/blob/ce87934/chain.go#L45

func Log

func Log(logger *slog.Logger) Middleware

Log is a middleware that logs request start, end, duration, and status.

func Recover

func Recover() Middleware

Recover is a middleware that recovers from panics in the delegate handler and prints a stack trace.

func RequestSize

func RequestSize(n int64) Middleware

RequestSize limits the size of incoming request bodies.

func Timeout

func Timeout(d time.Duration) Middleware

Timeout returns a new Middleware that times out each request after the given duration.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳