web

package
v1.19.7 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2021 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IPRateLimiter

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

IPRateLimiter imposes a rate limit per HTTP user IP.

func NewIPRateLimiter

func NewIPRateLimiter(config IPRateLimiterConfig) *IPRateLimiter

NewIPRateLimiter constructs an IPRateLimiter.

func (*IPRateLimiter) Burst

func (rl *IPRateLimiter) Burst() int

Burst returns the number of events that happen before the rate limit.

func (*IPRateLimiter) Duration

func (rl *IPRateLimiter) Duration() time.Duration

Duration returns the amount of time required between events.

func (*IPRateLimiter) Limit

func (rl *IPRateLimiter) Limit(next http.Handler) http.Handler

Limit applies a per IP rate limiting as an HTTP Handler.

func (*IPRateLimiter) Run

func (rl *IPRateLimiter) Run(ctx context.Context)

Run occasionally cleans old rate-limiting data, until context cancel.

type IPRateLimiterConfig

type IPRateLimiterConfig struct {
	Duration  time.Duration `help:"the rate at which request are allowed" default:"5m"`
	Burst     int           `help:"number of events before the limit kicks in" default:"5"`
	NumLimits int           `help:"number of IPs whose rate limits we store" default:"1000"`
}

IPRateLimiterConfig configures an IPRateLimiter.

Jump to

Keyboard shortcuts

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