Documentation
¶
Index ¶
Constants ¶
View Source
const MaxInt = int(MaxUint >> 1)
MaxInt holds the maximum int value
View Source
const MaxUint = ^uint(0)
MaxUint holds the maximum unsigned int value
Variables ¶
View Source
var ( ErrInvalidLimit = errors.New("Limit must be greater than zero") ErrInvalidInterval = errors.New("Interval must be greater than zero") ErrTokenFactoryNotDefined = errors.New("Token factory must be defined") )
Errors used throughout the codebase
Functions ¶
func DoWork ¶
func DoWork(r RateLimiter, workerCount int)
Types ¶
type Config ¶
type Config struct {
// Limit determines how many rate limit tokens can be active at a time
Limit int
// FixedInterval sets the fixed time window for a Fixed Window Rate Limiter
FixedInterval time.Duration
// Throttle is the min time between requests for a Throttle Rate Limiter
Throttle time.Duration
// TokenResetsAfter is the maximum amount of time a token can live before being
// forcefully released - if set to zero time then the token may live forever
TokenResetsAfter time.Duration
}
Config represents a rate limiter config object
type FixedWindowInterval ¶
type FixedWindowInterval struct {
// contains filtered or unexported fields
}
FixedWindowInterval represents a fixed window of time with a start / end time
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager implements a rate limiter interface.
type RateLimiter ¶
RateLimiter defines two methods for acquiring and releasing tokens
func NewFixedWindowRateLimiter ¶
func NewFixedWindowRateLimiter(conf *Config) (RateLimiter, error)
NewFixedWindowRateLimiter returns a fixed window rate limiter
func NewMaxConcurrencyRateLimiter ¶
func NewMaxConcurrencyRateLimiter(conf *Config) (RateLimiter, error)
NewMaxConcurrencyRateLimiter returns a max concurrency rate limiter
func NewThrottleRateLimiter ¶
func NewThrottleRateLimiter(conf *Config) (RateLimiter, error)
NewThrottleRateLimiter returns a throttle rate limiter
type Token ¶
type Token struct {
// The unique token ID
ID string
// The time at which the token was created
CreatedAt time.Time
// Defines the min amount of time the token must live before being released
ExpiresAt time.Time
}
Token represents a Rate Limit Token
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
fixed_window_rate_limiter
command
|
|
|
max_concurrency_rate_limiter
command
|
|
|
throttle_rate_limiter
command
|
Click to show internal directories.
Click to hide internal directories.