Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AgentConfig ¶
type AgentConfig struct {
Agent string `yaml:"agent"`
Schedule string `yaml:"schedule"`
Duration time.Duration `yaml:"duration"`
}
AgentConfig holds the limit configuration for a user agent.
type Agents ¶
Agents holds the cron limits for a set of user agents.
func ParseConfig ¶
ParseConfig interprets the configuration file and returns the set of agent limits.
type Cron ¶
type Cron struct {
*cronexpr.Expression
// contains filtered or unexported fields
}
Cron infers time limits based on a cron schedule.
type RateLimitConfig ¶ added in v0.17.0
type RateLimitConfig struct {
// Interval defines the duration of the sliding window.
Interval time.Duration
// MaxEvents defines the maximum number of events allowed in the interval.
MaxEvents int
// KeyPrefix is the prefix for Redis keys.
KeyPrefix string
}
RateLimitConfig holds the configuration for IP+UA rate limiting.
type RateLimiter ¶ added in v0.17.0
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter implements a distributed rate limiter using Redis sorted sets (ZSET). It maintains a sliding window of events for each IP+UA combination, where:
- Each event is stored in a ZSET with the timestamp as score
- Old events (outside the window) are automatically removed
- Keys automatically expire after the configured interval
The limiter considers a request to be rate-limited if the number of events in the current window exceeds MaxEvents.
func NewRateLimiter ¶ added in v0.17.0
func NewRateLimiter(pool *redis.Pool, config RateLimitConfig) *RateLimiter
NewRateLimiter creates a new rate limiter.