limit

package
v1.10.35 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2021 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	Unknown = iota
	Allowed
	HitQuota
	OverQuota
)

Variables

View Source
var ErrUnknownCode = errors.New("unknown status code")

Functions

This section is empty.

Types

type LimitOption

type LimitOption func(l *PeriodLimit)

func Align

func Align() LimitOption

type PeriodLimit

type PeriodLimit struct {
	// contains filtered or unexported fields
}

func NewPeriodLimit

func NewPeriodLimit(period, quota int, limitStore *redis.Redis, keyPrefix string,
	opts ...LimitOption) *PeriodLimit

func (*PeriodLimit) Take

func (h *PeriodLimit) Take(key string) (int, error)

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).

func (*TokenLimiter) AllowN

func (lim *TokenLimiter) AllowN(now time.Time, n int) bool

AllowN reports whether n events may happen at time now. Use this method if you intend to drop / skip events that exceed the rate rate. Otherwise use Reserve or Wait.

Jump to

Keyboard shortcuts

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