Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrAutoKeyAlreadyExists = errors.New("key already exists") ErrAutoKeyMissing = errors.New("key does not exist") )
var ( ErrKeyAlreadyExists = errorutil.NewWithTag("MultiLimiter", "key already exists") ErrKeyMissing = errorutil.NewWithTag("MultiLimiter", "key does not exist") )
Functions ¶
This section is empty.
Types ¶
type AutoLimiter ¶ added in v0.0.83
type AutoLimiter struct {
// contains filtered or unexported fields
}
AutoLimiter is an improved version of MultiLimiter with better memory management
func NewAutoLimiter ¶ added in v0.0.83
func NewAutoLimiter(ctx context.Context, opts ...AutoLimiterOption) *AutoLimiter
NewAutoLimiter creates a new auto limiter instance using functional options
func (*AutoLimiter) Add ¶ added in v0.0.83
func (e *AutoLimiter) Add(key string, opts ...AutoLimiterOption) error
Add creates a new rate limiter with custom settings (only for keys that need specific limits)
func (*AutoLimiter) AddAndTake ¶ added in v0.0.83
func (e *AutoLimiter) AddAndTake(key string, opts ...AutoLimiterOption) error
AddAndTake adds a key with custom settings if not present and then takes a token
func (*AutoLimiter) Remove ¶ added in v0.0.83
func (e *AutoLimiter) Remove(key string)
Remove completely removes a key and its options
func (*AutoLimiter) Stop ¶ added in v0.0.83
func (e *AutoLimiter) Stop(keys ...string)
Stop internal limiters with defined keys or all if no key is provided
func (*AutoLimiter) Take ¶ added in v0.0.83
func (e *AutoLimiter) Take(key string) error
Take one token from bucket - creates limiter automatically if it doesn't exist
type AutoLimiterOption ¶ added in v0.0.83
type AutoLimiterOption func(*AutoLimiter)
AutoLimiterOption is a function that configures the AutoLimiter
func WithDuration ¶ added in v0.0.83
func WithDuration(duration time.Duration) AutoLimiterOption
WithDuration sets the duration for the rate limiter
func WithMaxCount ¶ added in v0.0.83
func WithMaxCount(maxCount uint) AutoLimiterOption
WithMaxCount sets the maximum count for the rate limiter
func WithUnlimited ¶ added in v0.0.83
func WithUnlimited() AutoLimiterOption
WithUnlimited sets the limiter to unlimited mode
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
Limiter allows a burst of request during the defined duration
func NewLeakyBucket ¶ added in v0.0.43
NewUnlimited create a bucket with approximated unlimited tokens
func NewUnlimited ¶
NewUnlimited create a bucket with approximated unlimited tokens
func (*Limiter) SetDuration ¶ added in v0.0.33
GetLimit returns current rate limit per given duration
type MultiLimiter ¶ added in v0.0.3
type MultiLimiter struct {
// contains filtered or unexported fields
}
MultiLimiter is wrapper around Limiter than can limit based on a key
func NewMultiLimiter ¶ added in v0.0.3
func NewMultiLimiter(ctx context.Context, opts *Options) (*MultiLimiter, error)
NewMultiLimiter : Limits
func (*MultiLimiter) Add ¶ added in v0.0.3
func (m *MultiLimiter) Add(opts *Options) error
Add new bucket with key
func (*MultiLimiter) AddAndTake ¶ added in v0.0.6
func (m *MultiLimiter) AddAndTake(opts *Options)
AddAndTake adds key if not present and then takes token from bucket
func (*MultiLimiter) CanTake ¶ added in v0.0.9
func (m *MultiLimiter) CanTake(key string) bool
CanTake checks if the rate limiter with the given key has any token
func (*MultiLimiter) GetLimit ¶ added in v0.0.3
func (m *MultiLimiter) GetLimit(key string) (uint, error)
GetLimit returns current ratelimit of given key
func (*MultiLimiter) Stop ¶ added in v0.0.4
func (m *MultiLimiter) Stop(keys ...string)
Stop internal limiters with defined keys or all if no key is provided
func (*MultiLimiter) Take ¶ added in v0.0.3
func (m *MultiLimiter) Take(key string) error
Take one token from bucket returns error if key not present