Documentation ¶
Index ¶
- type Limiter
- func (l *Limiter) Allow(name string, maxn uint64, dur time.Duration) (count uint64, delay time.Duration, allow bool)
- func (l *Limiter) AllowHour(name string, maxn uint64) (count uint64, delay time.Duration, allow bool)
- func (l *Limiter) AllowMinute(name string, maxn uint64) (count uint64, delay time.Duration, allow bool)
- func (l *Limiter) AllowN(name string, maxn uint64, dur time.Duration, n int64) (count uint64, delay time.Duration, allow bool)
- func (l *Limiter) AllowRate(name string, rateLimit rate.Limit) (delay time.Duration, allow bool)
- func (l *Limiter) Reset(name string, dur time.Duration) error
- func (l *Limiter) ResetRate(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 Memcache is unavailable. Fallback *rate.Limiter // contains filtered or unexported fields }
Limiter controls how frequently events are allowed to happen.
func NewWithMemcache ¶
NewWithMemcache creats a Limiter
func (*Limiter) Allow ¶
func (l *Limiter) Allow(name string, maxn uint64, dur time.Duration) (count uint64, delay time.Duration, allow bool)
Allow is shorthand for AllowN(name, max, dur, 1).
func (*Limiter) AllowHour ¶
func (l *Limiter) AllowHour(name string, maxn uint64) (count uint64, delay time.Duration, allow bool)
AllowHour is shorthand for Allow(name, maxn, time.Hour).
func (*Limiter) AllowMinute ¶
func (l *Limiter) AllowMinute(name string, maxn uint64) (count uint64, delay time.Duration, allow bool)
AllowMinute is shorthand for Allow(name, maxn, time.Minute).
func (*Limiter) AllowN ¶
func (l *Limiter) AllowN(name string, maxn uint64, dur time.Duration, n int64) (count uint64, 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 duration dur, with each interaction incrementing the limit by n.
func (*Limiter) AllowRate ¶
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.