middleware

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package middleware provides HTTP middlewares.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chain

func Chain(handler http.Handler, middlewares ...Middleware) http.Handler

Chain applies a series of middlewares to an http.Handler. The middlewares are applied in reverse order, meaning the last middleware in the list will be the first to execute when handling an HTTP request.

func EnforceJSON

func EnforceJSON(next http.Handler) http.Handler

EnforceJSON is a middleware that ensures the incoming HTTP request has a Content-Type header set to "application/json". If the header is missing or invalid, it returns an appropriate error response (400 Bad Request or 415 Unsupported Media Type).

func Recovery

func Recovery(logger *log.Logger) func(next http.Handler) http.Handler

Recovery is a middleware that recovers from panics during HTTP request handling. It logs the panic and returns a 500 Internal Server Error response to the client. The logger parameter is used to log the panic details.

Types

type Middleware

type Middleware func(http.Handler) http.Handler

Middleware is a type that represents an HTTP middleware function. It takes an http.Handler and returns a new http.Handler that wraps the original.

Jump to

Keyboard shortcuts

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