Documentation
¶
Overview ¶
Package algorithm defines core interfaces and shared data structures for rate limiting algorithm strategies.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Algorithm ¶
type Algorithm interface {
// Name returns the unique identifier string of the algorithm strategy.
Name() string
// EvaluateMemory evaluates the rate limit state in local RAM.
EvaluateMemory(now time.Time, state *State, limit int64, window time.Duration) Result
// RedisScript returns the atomic Lua script for Redis distribution.
RedisScript() string
}
Algorithm defines the interface for pluggable rate limiting algorithms. Algorithms provide both a local in-memory evaluation implementation and an atomic Redis Lua script.
type Result ¶
type Result struct {
// Allowed indicates whether the current request is permitted under the rate limit quota.
Allowed bool
// Limit is the maximum request capacity configured for the time window.
Limit int64
// Remaining is the remaining request quota available in the active window.
Remaining int64
// ResetIn specifies the duration until the rate limit quota resets or recovers.
ResetIn time.Duration
}
Result represents the outcome of a rate limit evaluation.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package fixedwindow implements the Fixed Window rate limiting algorithm.
|
Package fixedwindow implements the Fixed Window rate limiting algorithm. |
|
Package leakybucket implements the Leaky Bucket rate limiting algorithm for traffic shaping.
|
Package leakybucket implements the Leaky Bucket rate limiting algorithm for traffic shaping. |
|
Package slidingcounter implements the Sliding Window Counter rate limiting algorithm.
|
Package slidingcounter implements the Sliding Window Counter rate limiting algorithm. |
|
Package slidinglog implements the Sliding Window Log rate limiting algorithm.
|
Package slidinglog implements the Sliding Window Log rate limiting algorithm. |
|
Package tokenbucket implements the Token Bucket rate limiting algorithm.
|
Package tokenbucket implements the Token Bucket rate limiting algorithm. |
Click to show internal directories.
Click to hide internal directories.