ratelimit

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package ratelimit defines the rate-limit integration point of Auth-All. Auth-All does not require a specific backend.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Key

type Key struct {
	Operation Operation
	IP        string
	Email     string
	UserID    string
	Provider  string
}

Key identifies one rate-limited attempt. Fields are set when relevant.

type Limiter

type Limiter interface {
	Allow(ctx context.Context, key Key) (bool, error)
}

Limiter decides whether one attempt can proceed.

type LimiterFunc

type LimiterFunc func(ctx context.Context, key Key) (bool, error)

LimiterFunc adapts a function to the Limiter interface.

func (LimiterFunc) Allow

func (f LimiterFunc) Allow(ctx context.Context, k Key) (bool, error)

Allow implements Limiter.

type Memory

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

Memory is an in-process fixed-window limiter.

Memory is for local development and tests only. It is not sufficient for a distributed production deployment because each process keeps its own counters.

func NewMemory

func NewMemory(limit int, window time.Duration) *Memory

NewMemory returns an in-process limiter that allows limit attempts per window.

func (*Memory) Allow

func (m *Memory) Allow(_ context.Context, k Key) (bool, error)

Allow implements Limiter.

type Operation

type Operation string

Operation names a sensitive flow.

const (
	OpSignIn           Operation = "sign-in"
	OpSignUp           Operation = "sign-up"
	OpPasswordForgot   Operation = "password-forgot"
	OpEmailVerify      Operation = "email-verification-send"
	OpMagicLinkRequest Operation = "magic-link-request"
	OpPasswordChange   Operation = "password-change"
	OpEmailChange      Operation = "email-change"
	OpUserDelete       Operation = "user-delete"
	OpTOTP             Operation = "totp"
)

Sensitive operations.

Jump to

Keyboard shortcuts

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