middleware

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package middleware provides configurable middleware and predefined lists, such as Minimal, Default and DefaultWithSentry.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CORS added in v0.1.1

func CORS(allowedOrigins []string, useSentry bool) shared.Middleware

CORS is middleware used to apply CORS settings.

func Default

func Default(
	logger *slog.Logger,
	allowedOrigins []string,
) ([]alice.Constructor, error)

Default provides a predefined chain of useful middleware. Being:

func DefaultWithSentry added in v0.1.1

func DefaultWithSentry(
	logger *slog.Logger,
	allowedOrigins []string,
	env string,
	sentryClientOptions sentry.ClientOptions,
) ([]alice.Constructor, error)

DefaultWithSentry provides a predefined chain of useful middleware. Being:

func Logger

func Logger(logger *slog.Logger) shared.Middleware

Logger is middleware used to add a logger to the context and log every request and their duration.

func Minimal

func Minimal(logger *slog.Logger) []alice.Constructor

Minimal provides a predefined chain of useful middleware. Being:

func RateLimit

func RateLimit(
	rps rate.Limit,
	bucketSize int,
	cleanupTimer time.Duration,
	removeAfter time.Duration,
) shared.Middleware

RateLimit is middleware used to rate limit requests by clients identified by IP.

func Recover

func Recover(logger *slog.Logger) shared.Middleware

Recover is middleware used to recover from a panic.

func ShowErrors added in v0.1.1

func ShowErrors() shared.Middleware

ShowErrors is middleware used to show errors. When used errors handled by httptools.ServerErrorResponse will be shown. Otherwise these will be hidden.

Types

This section is empty.

Jump to

Keyboard shortcuts

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