rate_limiter

package
v5.3.3 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2024 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Limiter added in v5.3.0

type Limiter struct {
	// Limit and Burst are read-only.
	Limit rate.Limit
	Burst int
	// contains filtered or unexported fields
}

func NewRateLimiter

func NewRateLimiter(limit rate.Limit, burst int) *Limiter

NewRateLimiter creates a new client rate limiter. limit and burst should be greater than zero. See rate.Limiter for more details. Limiter has a internal gc which will run and remove old client entries every 1m. If the token refill time (burst/limit) is greater than 1m, the actual average qps limit may be higher than expected because the client status may be deleted and re-initialized.

func (*Limiter) Allow added in v5.3.0

func (l *Limiter) Allow(unmappedAddr netip.Addr) bool

maskedUnmappedP must be a masked prefix and contain a unmapped addr.

func (*Limiter) Close added in v5.3.0

func (l *Limiter) Close() error

func (*Limiter) ForEach added in v5.3.0

func (l *Limiter) ForEach(doFunc func(unmappedAddr netip.Addr, r *rate.Limiter) (doBreak bool)) (doBreak bool)

func (*Limiter) Len added in v5.3.0

func (l *Limiter) Len() int

Len returns current number of entries in the Limiter.

Jump to

Keyboard shortcuts

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