Documentation ¶
Overview ¶
Package middleware provides configurable middleware and predefined lists, such as Minimal, Default and DefaultWithSentry.
Index ¶
- func CORS(allowedOrigins []string, useSentry bool) shared.Middleware
- func Default(logger *slog.Logger, allowedOrigins []string) ([]alice.Constructor, error)
- func DefaultWithSentry(logger *slog.Logger, allowedOrigins []string, env string, ...) ([]alice.Constructor, error)
- func Logger(logger *slog.Logger) shared.Middleware
- func Minimal(logger *slog.Logger) []alice.Constructor
- func RateLimit(rps rate.Limit, bucketSize int, cleanupTimer time.Duration, ...) shared.Middleware
- func Recover(logger *slog.Logger) shared.Middleware
- func ShowErrors() shared.Middleware
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 ¶
Default provides a predefined chain of useful middleware. Being:
- All middleware from Minimal
- helmet.Helmet
- CORS
- RateLimit
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:
- All middleware from Default
- sentrytools.Middleware
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.