middlewares

package
v0.0.0-...-bd94320 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Logger

func Logger(next http.Handler) http.Handler

Logger is a middleware that logs incoming requests and logging some of the details to slog.

Types

type Auth

type Auth struct {
	Resolver *jwtresolver.JWTResolver
}

Auth is a stateful middleware that checks if user is authorized. If user is authorized, it adds user ID to the requests context. Otherwise, it returns an error.

func (*Auth) Handle

func (a *Auth) Handle(next http.Handler) http.Handler

Handle method handles incoming requests.

type CtxKey

type CtxKey int
const (
	KeyUserID CtxKey = iota
)

type Middleware

type Middleware func(http.Handler) http.Handler

Middleware is a function that takes an http.Handler and returns an http.Handler.

func MakeChain

func MakeChain(mws ...Middleware) Middleware

MakeChain wraps a list of middlewares in a chain. Chain works like FIFO stack of middlewares.

Jump to

Keyboard shortcuts

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