ratelimit

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GlobalLimiter

func GlobalLimiter(cfg Config) func(http.Handler) http.Handler

GlobalLimiter creates a global rate limiter middleware.

func IPLimiter

func IPLimiter(cfg Config) func(http.Handler) http.Handler

IPLimiter creates a per-IP rate limiter middleware (fallback).

func WalletLimiter

func WalletLimiter(cfg Config) func(http.Handler) http.Handler

WalletLimiter creates a per-wallet rate limiter middleware. It extracts wallet address from various request sources (headers, body, query params).

Types

type Config

type Config struct {
	// Global rate limiting (across all users)
	GlobalEnabled bool
	GlobalLimit   int           // requests per window
	GlobalWindow  time.Duration // time window
	GlobalBurst   int           // burst capacity

	// Per-wallet rate limiting (identified by wallet address)
	PerWalletEnabled bool
	PerWalletLimit   int
	PerWalletWindow  time.Duration
	PerWalletBurst   int

	// Per-IP rate limiting (fallback when wallet not identified)
	PerIPEnabled bool
	PerIPLimit   int
	PerIPWindow  time.Duration
	PerIPBurst   int

	// Metrics collector (optional)
	Metrics *metrics.Metrics
}

Config holds rate limiting configuration.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible default rate limits. These are generous limits designed to stop obvious spam while not restricting legitimate use.

Jump to

Keyboard shortcuts

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