throttle

package
v1.42.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 12 Imported by: 1 module, 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

Overview

Package throttle makes a key wait longer after each try in a row: wrong passwords at the login and on the OAuth consent page, accounts created from one address at the sign-up. The tries are kept in the base (throttles), so a restart forgets none: the consent page faces the Internet.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RetryAfter

func RetryAfter(wait time.Duration) string

RetryAfter is wait in whole seconds, rounded up, for the Retry-After header.

Types

type Throttle

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

Throttle counts the tries in a row of each key, under its name.

func New

func New(db bun.IDB, name, message string) *Throttle

New gives a throttle whose keys are counted under name, and whose 429 says message.

func Passwords

func Passwords(db bun.IDB) *Throttle

Passwords counts the wrong passwords: the login and the OAuth consent page share the count of an address.

func (*Throttle) Blocked

func (t *Throttle) Blocked(w http.ResponseWriter, r *http.Request, key string) bool

Blocked answers 429 with Retry-After while key waits, else counts the try (Try).

func (*Throttle) Forgive

func (t *Throttle) Forgive(ctx context.Context, key string)

Forgive takes back the try Try counted, when it did not count.

func (*Throttle) Reset

func (t *Throttle) Reset(ctx context.Context, key string)

Reset forgets the tries of key.

func (*Throttle) Try

func (t *Throttle) Try(ctx context.Context, key string) (time.Duration, error)

Try counts a try for key before it runs, and gives 0; or, while key waits, how long it has left, without counting. One statement: tries sent at once cannot all pass while argon2id runs. The caller resets on a good password, forgives on another error.

Jump to

Keyboard shortcuts

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