middleware

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package middleware provides HTTP middleware for the REST API

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RateLimitMiddleware

func RateLimitMiddleware(limiter *RateLimiter) func(http.Handler) http.Handler

RateLimitMiddleware creates HTTP middleware for rate limiting

Types

type RateLimiter

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

RateLimiter provides token bucket rate limiting

func DefaultAPIRateLimiter

func DefaultAPIRateLimiter() *RateLimiter

DefaultAPIRateLimiter returns a rate limiter for general API endpoints

func DefaultLoginRateLimiter

func DefaultLoginRateLimiter() *RateLimiter

DefaultLoginRateLimiter returns a rate limiter for login endpoints

func NewRateLimiter

func NewRateLimiter(maxTokens int, refillRate time.Duration) *RateLimiter

NewRateLimiter creates a new rate limiter

func (*RateLimiter) Allow

func (rl *RateLimiter) Allow(ip string) bool

Allow checks if a request from the given IP is allowed

func (*RateLimiter) Cleanup

func (rl *RateLimiter) Cleanup(maxAge time.Duration)

Cleanup removes stale entries older than the given duration

func (*RateLimiter) StartAutoCleanup

func (rl *RateLimiter) StartAutoCleanup(interval time.Duration, maxAge time.Duration)

StartAutoCleanup starts a background goroutine that periodically cleans up stale entries

Jump to

Keyboard shortcuts

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