middleware

package
v0.0.0-...-7f6939c Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InMemoryRateLimiter

type InMemoryRateLimiter struct {
	// contains filtered or unexported fields
}

InMemoryRateLimiter provides fast in-memory rate limiting

type RateLimitConfig

type RateLimitConfig struct {
	// Login endpoint limits
	LoginMaxAttempts   int           // Max login attempts per window
	LoginWindow        time.Duration // Time window for login attempts
	LoginBlockDuration time.Duration // Duration to block after exceeding limit

	// Logout endpoint limits
	LogoutMaxAttempts int           // Max logout attempts per window
	LogoutWindow      time.Duration // Time window for logout attempts

	// General API limits
	GeneralMaxRequests int           // Max requests per window for general endpoints
	GeneralWindow      time.Duration // Time window for general requests
}

RateLimitConfig holds configuration for rate limiting

func DefaultRateLimitConfig

func DefaultRateLimitConfig() *RateLimitConfig

DefaultRateLimitConfig returns default rate limiting configuration

type RateLimitEntry

type RateLimitEntry struct {
	Attempts     int
	WindowStart  time.Time
	BlockedUntil time.Time
}

RateLimitEntry tracks rate limit state for an IP

type RateLimiter

type RateLimiter struct {
	// contains filtered or unexported fields
}

RateLimiter provides rate limiting for API endpoints

func NewRateLimiter

func NewRateLimiter(db *sqlx.DB, config *RateLimitConfig) *RateLimiter

NewRateLimiter creates a new rate limiter

func (*RateLimiter) Cleanup

func (rl *RateLimiter) Cleanup()

Cleanup removes expired entries from in-memory cache

func (*RateLimiter) IsIPBlockedFromLogin

func (rl *RateLimiter) IsIPBlockedFromLogin(clientIP string) (bool, time.Time)

IsIPBlockedFromLogin checks if an IP is blocked from login attempts in the database

func (*RateLimiter) RateLimitMiddleware

func (rl *RateLimiter) RateLimitMiddleware(endpointType string) func(http.Handler) http.Handler

RateLimitMiddleware returns an HTTP middleware for rate limiting

func (*RateLimiter) RecordLoginAttempt

func (rl *RateLimiter) RecordLoginAttempt(clientIP string, _ bool)

RecordLoginAttempt records a login attempt (for persistent tracking)

Jump to

Keyboard shortcuts

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