Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Limit ¶
func LimitPerHour ¶
LimitPerHour creates a TokenLimit configuration for a rate limit that allows a specified number of tokens to be refilled per hour with a burst capacity equal to the refill rate. Example: LimitPerHour(18000) creates a TokenLimit allowing 18000 tokens per hour with a burst capacity of 18000.
func LimitPerMinute ¶
LimitPerMinute creates a TokenLimit configuration for a rate limit that allows a specified number of tokens to be refilled per minute with a burst capacity equal to the refill rate. Example: LimitPerMinute(300) creates a TokenLimit allowing 300 tokens per minute with a burst capacity of 300.
func LimitPerSecond ¶
LimitPerSecond creates a TokenLimit configuration for a rate limit that allows a specified number of tokens to be refilled per second with a burst capacity equal to the refill rate. Example: LimitPerSecond(5) creates a TokenLimit allowing 5 tokens per second with a burst capacity of 5.
type Limiter ¶
type Limiter struct { Options Options // contains filtered or unexported fields }
func NewLimiter ¶
type Options ¶
type Options struct { // KeyPrefix is the prefix for keys managed by the limiter. // By default, it is set to "RATE_LIMIT", but it can be customized. KeyPrefix string // KeyCleanupInterval is the interval at which expired keys are cleaned up. // Default is 10 seconds. KeyCleanupInterval time.Duration // KeyCleanupBatchLimit is the maximum number of keys to delete per cleanup run. // Default is 10000. KeyCleanupBatchLimit int }
Options holds the configuration settings for the LeakyBucketLimiter. It includes parameters for key prefix, cleanup intervals, and batch limits.
func DefaultOptions ¶
func DefaultOptions() Options
DefaultOptions returns an Options struct initialized with default values for limiter configuration settings. The default values are designed to provide a basic configuration suitable for many scenarios. Each field in the Options struct is set to a default value, as documented below:
Defaults:
- KeyPrefix: The prefix used for keys managed by the limiter. Default is set to "RATE_LIMIT".
- KeyCleanupInterval: The interval between cleanup operations for expired key cleanup. Default is 10 seconds.
- KeyCleanupBatchLimit: The maximum number of keys to delete during each cleanup run. Default is 10000.