ratelimit

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Ratelimits are only used for login and other endpoints that can be heavily abused

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultIdentifier

func DefaultIdentifier(r *http.Request) string

Types

type Limit

type Limit struct {
	// Exceeded is true if the ratelimit has been exceeded
	Exceeded bool
	// Made is the number of requests made in the ratelimit
	Made int
	// Remaining is the number of requests remaining in the ratelimit
	Remaining int
	// TimeToReset is the time remaining until the ratelimit resets
	TimeToReset time.Duration
	// GotIdentifier is the identifier of the ratelimit
	GotIdentifier string
	// MaxRequests is the maximum number of requests allowed in the interval specified by Expiry for the bucket
	MaxRequests int
	// Bucket is the bucket to use for the ratelimit
	Bucket string
}

Limit is used to check if the ratelimit has been exceeded

func (Limit) Headers

func (l Limit) Headers() map[string]string

type Ratelimit

type Ratelimit struct {
	// Expiry is the time for the ratelimit to expire
	Expiry time.Duration
	// MaxRequests is the maximum number of requests allowed in the interval specified by Expiry for the bucket
	MaxRequests int
	// Bucket is the bucket to use for the ratelimit
	Bucket string
	// Identifier is the identifier of the ratelimit, otherwise DefaultIdentifier is used
	Identifier func(r *http.Request) string
}

func (Ratelimit) Limit

func (rl Ratelimit) Limit(ctx context.Context, r *http.Request) (Limit, error)

Jump to

Keyboard shortcuts

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