middleware

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SessionAutoStart   bool = true
	NoSessionAutoStart bool = false
)

Variables

This section is empty.

Functions

func DefaultAllowedHeaders

func DefaultAllowedHeaders() []string

func DefaultAllowedMethods

func DefaultAllowedMethods() []string

func NewBasicAuth

func NewBasicAuth(username, password string) ctx.Handler

func NewCors

func NewCors(options CorsOptions) ctx.Handler

func NewLog

func NewLog(l loggerService) ctx.Handler

func NewRateLimit

func NewRateLimit(cfg RateLimitConfig) ctx.Handler

NewRateLimit returns a middleware that limits requests per IP address using a fixed-window counter algorithm.

func NewRecovery

func NewRecovery() ctx.Handler

NewRecovery returns a middleware that recovers from panics in downstream handlers and converts them into a 500 Internal Server Error response.

func NewSecurityHeaders

func NewSecurityHeaders() ctx.Handler

NewSecurityHeaders adds common security headers to all responses.

func NewSession

func NewSession(cacheSvc cache.Service, autostart bool) ctx.Handler

func NewTimeout

func NewTimeout(d time.Duration) ctx.Handler

NewTimeout returns a middleware that cancels the request context after the given duration. If the handler exceeds the deadline, a 503 Service Unavailable error is returned.

func StartSession

func StartSession(c ctx.Ctx, cacheSvc cache.Service) error

Types

type CorsOptions

type CorsOptions struct {
	Origin         string
	AllowedMethods []string
	AllowedHeaders []string
}

func NewCorsOptions

func NewCorsOptions() CorsOptions

type RateLimitConfig

type RateLimitConfig struct {
	// Maximum number of requests allowed within the window
	Max int

	// Time window for counting requests
	Window time.Duration

	// CleanupInterval controls how often expired entries are removed.
	// Defaults to 2x Window if zero.
	CleanupInterval time.Duration
}

RateLimitConfig configures the rate limiter.

func DefaultRateLimitConfig

func DefaultRateLimitConfig() RateLimitConfig

DefaultRateLimitConfig returns a config allowing 60 requests per minute.

Jump to

Keyboard shortcuts

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