Documentation ¶
Index ¶
Constants ¶
View Source
const ( // Unknown means not initialized state. Unknown = iota // Allowed means allowed state. Allowed // HitQuota means this request exactly hit the quota. HitQuota // OverQuota means passed the quota. OverQuota )
Variables ¶
View Source
var ErrUnknownCode = errors.New("unknown status code")
ErrUnknownCode is an error that represents unknown status code.
Functions ¶
This section is empty.
Types ¶
type PeriodLimit ¶
type PeriodLimit struct {
// contains filtered or unexported fields
}
A PeriodLimit is used to limit requests during a period of time.
func NewPeriodLimit ¶
func NewPeriodLimit(period, quota int, limitStore *redis.Redis, keyPrefix string, opts ...PeriodOption) *PeriodLimit
NewPeriodLimit returns a PeriodLimit with given parameters.
type PeriodOption ¶
type PeriodOption func(l *PeriodLimit)
PeriodOption defines the method to customize a PeriodLimit.
func Align ¶
func Align() PeriodOption
Align returns a func to customize a PeriodLimit with alignment.
type TokenLimiter ¶
type TokenLimiter struct {
// contains filtered or unexported fields
}
A TokenLimiter controls how frequently events are allowed to happen with in one second.
func NewTokenLimiter ¶
func NewTokenLimiter(rate, burst int, store *redis.Redis, key string) *TokenLimiter
NewTokenLimiter returns a new TokenLimiter that allows events up to rate and permits bursts of at most burst tokens.
func (*TokenLimiter) Allow ¶
func (lim *TokenLimiter) Allow() bool
Allow is shorthand for AllowN(time.Now(), 1).
Click to show internal directories.
Click to hide internal directories.