ratelimit

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package ratelimit holds the token buckets behind kit's default rate limit and plugins/ratelimit: per key, up to burst requests at once, refilled at a steady rate.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Limiter

type Limiter struct {

	// Now is the clock; tests replace it.
	Now func() time.Time
	// contains filtered or unexported fields
}

Limiter limits how often each key may act. It's safe for concurrent use.

func New

func New(perSecond, burst float64) *Limiter

New returns a Limiter allowing perSecond actions a second, in bursts of up to burst.

func (*Limiter) Sweep

func (l *Limiter) Sweep(stop <-chan struct{})

Sweep drops buckets that have refilled completely, every minute until stop is closed, so memory stays bounded.

func (*Limiter) Take

func (l *Limiter) Take(k string) (time.Duration, bool)

Take spends a token for k, or reports how long until one is available.

Jump to

Keyboard shortcuts

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