rate

package
v0.0.0-...-53bd342 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Every

func Every(interval time.Duration) float64

Every converts a minimum time interval between events to a requests-per-second value.

Types

type Limiter

type Limiter struct {
	Expiry   int     // Expressed in minutes. Clients older than this value will be cleaned.
	Burst    int     // How much tokens can be consumed by a client in one request.
	LimitRPS float64 // Expressed in requests per second.
	// contains filtered or unexported fields
}

Limiter leverages the std rate package to limit every client request. It assumes that the not allowed requests are DROPPED ! The alternative, to not drop requests, would be to use `Reserve()` instead of `Allow()`.

func NewLimiter

func NewLimiter(burst int, expiry int, limitRPS float64) *Limiter

NewLimiter constructs a new rate limiter with the passed options and returns it.

func (*Limiter) Check

func (l *Limiter) Check(id string) bool

Check updates the limiter for the passed client and checks whether the client request can be processed or it has exceeded the limit.

Jump to

Keyboard shortcuts

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