ratelimit

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package ratelimit limits events per key (an address, a user name) with a bounded memory: past the maximum, keys back to their initial state are dropped first (nothing is lost), then the least recently seen.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Keyed

type Keyed[K comparable] struct {
	// contains filtered or unexported fields
}

Keyed allows burst events at once per key, then one every period.

func New

func New[K comparable](every time.Duration, burst, max int) *Keyed[K]

New returns a limiter keeping at most max keys.

func (*Keyed[K]) Allow

func (l *Keyed[K]) Allow(key K, now time.Time) bool

Allow reports whether one more event of key may happen at now.

func (*Keyed[K]) Forget

func (l *Keyed[K]) Forget(key K)

Forget resets a key, e.g. after a successful sign in.

func (*Keyed[K]) Len

func (l *Keyed[K]) Len() int

Len is the number of keys held.

Jump to

Keyboard shortcuts

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