middlewares

package
v0.34.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithCSRF

func WithCSRF(cfg CSRFConfig, next http.HandlerFunc) http.HandlerFunc

WithCSRF wraps an http.HandlerFunc with CSRF validation logic. If CSRF is disabled, the handler is executed directly. If validation fails, it responds with the same payload used previously in the handlers and does not call the wrapped handler.

func WithRateLimit

func WithRateLimit(cfg RateLimitConfig, next http.HandlerFunc) http.HandlerFunc

WithRateLimit wraps an http.HandlerFunc with rate limiting logic.

Types

type CSRFConfig

type CSRFConfig struct {
	Enabled  bool
	Validate func(r *http.Request) bool
}

CSRFConfig holds configuration for CSRF validation.

type RateLimitConfig

type RateLimitConfig struct {
	// Check should perform the actual rate limit check. It should return true if
	// the request is allowed to proceed. If it returns false, it is assumed to
	// have already written the appropriate HTTP response.
	Check func(w http.ResponseWriter, r *http.Request, endpoint string) bool

	// Endpoint is the logical endpoint name used for rate limiting, e.g.
	// "login", "register", etc.
	Endpoint string
}

RateLimitConfig holds configuration for rate limiting.

Jump to

Keyboard shortcuts

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