ratelimit

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package ratelimit provides rate limiting functionality for email authentication.

This package implements a token bucket algorithm to prevent abuse of magic link emails by limiting how many times a user can request login links within a time window. Currently used exclusively for email authentication send rate limiting.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Limiter

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

Limiter implements a simple token bucket rate limiter backed by KVS Currently used to rate limit email authentication magic link sends.

func NewLimiter

func NewLimiter(rate int, interval time.Duration, kvsStore kvs.Store) *Limiter

NewLimiter creates a new rate limiter backed by KVS rate: number of allowed requests interval: time window for the rate

func (*Limiter) Allow

func (l *Limiter) Allow(key string) bool

Allow checks if a request is allowed for the given key

func (*Limiter) Cleanup

func (l *Limiter) Cleanup(maxAge time.Duration)

Cleanup removes old buckets that haven't been used recently

func (*Limiter) Reset

func (l *Limiter) Reset(key string)

Reset clears the rate limit for a specific key

Jump to

Keyboard shortcuts

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