limiter

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2020 License: MIT Imports: 6 Imported by: 0

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 Limiter

type Limiter interface {
	Allow() bool
	AllowN(int) bool
}

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL