Documentation
¶
Index ¶
- type Limiter
- func (l *Limiter) Allow(ctx context.Context, name string, maxn int64, period time.Duration) (count int64, delay time.Duration, allow bool)
- func (l *Limiter) AllowHour(ctx context.Context, name string, maxn int64) (count int64, delay time.Duration, allow bool)
- func (l *Limiter) AllowMinute(ctx context.Context, name string, maxn int64) (count int64, delay time.Duration, allow bool)
- func (l *Limiter) AllowN(ctx context.Context, name string, maxn int64, period time.Duration, n int64) (count int64, delay time.Duration, allow bool)
- func (l *Limiter) AllowRate(ctx context.Context, name string, rateLimit rate.Limit) (delay time.Duration, allow bool)
- func (l *Limiter) Reset(ctx context.Context, name string, period time.Duration) error
- func (l *Limiter) ResetRate(ctx context.Context, name string, rateLimit rate.Limit) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Limiter ¶
type Limiter struct {
// Optional fallback limiter used when Redis is unavailable.
Fallback *rate.Limiter
// contains filtered or unexported fields
}
Limiter controls how frequently events are allowed to happen.
func NewLimiter ¶
func NewLimiter(redis rediser) *Limiter
func (*Limiter) Allow ¶
func (l *Limiter) Allow(ctx context.Context, name string, maxn int64, period time.Duration) (count int64, delay time.Duration, allow bool)
Allow is shorthand for AllowN(name, max, period, 1).
func (*Limiter) AllowHour ¶
func (l *Limiter) AllowHour(ctx context.Context, name string, maxn int64) (count int64, delay time.Duration, allow bool)
AllowHour is shorthand for Allow(name, maxn, time.Hour).
func (*Limiter) AllowMinute ¶
func (l *Limiter) AllowMinute(ctx context.Context, name string, maxn int64) (count int64, delay time.Duration, allow bool)
AllowMinute is shorthand for Allow(name, maxn, time.Minute).
func (*Limiter) AllowN ¶
func (l *Limiter) AllowN( ctx context.Context, name string, maxn int64, period time.Duration, n int64, ) (count int64, delay time.Duration, allow bool)
AllowN reports whether an event with given name may happen at time now. It allows up to maxn events within period, with each interaction incrementing the limit by n.
func (*Limiter) AllowRate ¶
func (l *Limiter) AllowRate(ctx context.Context, name string, rateLimit rate.Limit) (delay time.Duration, allow bool)
AllowRate reports whether an event may happen at time now. It allows up to rateLimit events each second.
Click to show internal directories.
Click to hide internal directories.