Documentation
¶
Index ¶
Constants ¶
View Source
const ( FormatInf = "-1~S~1" FormatZero = "0~S~1" )
Variables ¶
View Source
var ( ErrFormat = errors.New("limiter format error") ErrPeriod = errors.New("period error") )
Functions ¶
This section is empty.
Types ¶
type TokenLimiter ¶
type TokenLimiter struct {
// contains filtered or unexported fields
}
func NewTokenLimiter ¶
func NewTokenLimiter(format string) (*TokenLimiter, error)
if rate is 10 per second and burst is 20, the format is "10~S~20". if first part is 0, it will reject all events. if first part is less than 0, it will allow all events.
func (*TokenLimiter) Allow ¶
func (l *TokenLimiter) Allow() bool
func (*TokenLimiter) AllowN ¶
func (l *TokenLimiter) AllowN(n int) bool
Click to show internal directories.
Click to hide internal directories.