ratelimiter

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthLimiter

type AuthLimiter interface {
	AllowLoginAttempt(ctx context.Context, ip net.IP, email string) (bool, error)
	AllowSignupAttempt(ctx context.Context, ip net.IP, email string) (bool, error)
}

func NewInMemoryLimiter

func NewInMemoryLimiter(cfg LimiterConfig) AuthLimiter

type InMemoryLimiter

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

func (*InMemoryLimiter) AllowLoginAttempt

func (l *InMemoryLimiter) AllowLoginAttempt(_ context.Context, ip net.IP, email string) (bool, error)

func (*InMemoryLimiter) AllowSignupAttempt

func (l *InMemoryLimiter) AllowSignupAttempt(_ context.Context, ip net.IP, email string) (bool, error)

type LimiterConfig

type LimiterConfig struct {
	LoginIPLimit     int
	LoginIPWindow    time.Duration
	LoginEmailLimit  int
	LoginEmailWindow time.Duration

	SignupIPLimit     int
	SignupIPWindow    time.Duration
	SignupEmailLimit  int
	SignupEmailWindow time.Duration

	CleanupEvery int
	MaxEntries   int
}

type RateLimitedError

type RateLimitedError struct {
	RetryAfter time.Duration
	Scope      string // "login:ip", "login:email", "signup:ip", "signup:email"
}

RateLimitedError is returned when the caller should reject the attempt. RetryAfter can be used to set HTTP Retry-After header or show a UI message.

func IsRateLimited

func IsRateLimited(err error) (*RateLimitedError, bool)

func (*RateLimitedError) Error

func (e *RateLimitedError) Error() string

Jump to

Keyboard shortcuts

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