web

package
v1.46.0-rc Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRequestIP added in v1.34.1

func GetRequestIP(r *http.Request) (ip string, err error)

GetRequestIP gets the original IP address of the request by handling the request headers.

Types

type RateLimiter added in v1.39.4

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

RateLimiter imposes a rate limit per key.

func NewIPRateLimiter

func NewIPRateLimiter(config RateLimiterConfig) *RateLimiter

NewIPRateLimiter constructs a RateLimiter that limits based on IP address.

func NewRateLimiter added in v1.39.4

func NewRateLimiter(config RateLimiterConfig, keyFunc func(*http.Request) (string, error)) *RateLimiter

NewRateLimiter constructs a RateLimiter.

func (*RateLimiter) Burst added in v1.39.4

func (rl *RateLimiter) Burst() int

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

func (*RateLimiter) Duration added in v1.39.4

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

Duration returns the amount of time required between events.

func (*RateLimiter) Limit added in v1.39.4

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

Limit applies per-key rate limiting as an HTTP Handler.

func (*RateLimiter) Run added in v1.39.4

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

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

type RateLimiterConfig added in v1.39.4

type RateLimiterConfig 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" testDefault:"3"`
	NumLimits int           `help:"number of clients whose rate limits we store" default:"1000" testDefault:"10"`
}

RateLimiterConfig configures a RateLimiter.

Jump to

Keyboard shortcuts

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