Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
func (*Limiter) Allow ¶
func (l *Limiter) Allow(ctx context.Context, cost, rate, window int64, key string) ( bool, func(context.Context) error, error, )
Allow returns true if the limit is not exceeded, false otherwise.
func (*Limiter) AllowAfter ¶ added in v0.26.0
func (l *Limiter) AllowAfter(ctx context.Context, cost, rate, window int64, key string) ( bool, time.Duration, func(context.Context) error, error, )
AllowAfter returns true if the limit is not exceeded, false otherwise. Additionally, it returns the time.Duration until the next allowed request.
type Option ¶
type Option func(*Limiter)
Option is a functional option for the limiter, see With* functions for reference
func WithInMemoryGCRA ¶
WithInMemoryGCRA allows to use the GCRA algorithm (in-memory) with the specified burst or with the burst as rate if the provided burst is <= 0
func WithRedisGCRA ¶
WithRedisGCRA allows to use the GCRA algorithm (Redis version) with the specified burst or with the burst as rate if the provided burst is <= 0
func WithRedisSortedSet ¶
func WithRedisSortedSet(rc *redis.Client) Option
WithRedisSortedSet allows to use the Redis SortedSet algorithm for rate limiting
func WithStatsCollector ¶
func WithStatsCollector(sc statsCollector) Option
WithStatsCollector allows to setup a stats collector for the limiter