ratelimit

package
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2021 License: Apache-2.0, Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLimiter

func NewLimiter(opts ...limiterOption) web.FilterFunc

NewLimiter return FilterFunc, the limiter enables rate limit according to the configuration.

func NewTokenBucket

func NewTokenBucket(opts ...bucketOption) bucket

NewTokenBucket return an bucket that implements token bucket

func RemoteIPSessionKey

func RemoteIPSessionKey(r *http.Request) string

func WithBucketFactory

func WithBucketFactory(f func(opts ...bucketOption) bucket) limiterOption

WithBucketFactory return limiterOption. WithBucketFactory customize the implementation of Bucket.

func WithCapacity

func WithCapacity(c uint) limiterOption

WithCapacity return limiterOption. WithCapacity config the capacity size. The bucket with a capacity of n has n tokens after initialization. The capacity defines how many requests a client can make in excess of the rate.

func WithRate

func WithRate(r time.Duration) limiterOption

WithRate return limiterOption. WithRate config how long it takes to generate a token.

func WithRejectionResponse

func WithRejectionResponse(resp RejectionResponse) limiterOption

WithRejectionResponse return limiterOption. WithRejectionResponse customize the response for the request rejected by the limiter.

func WithSessionKey

func WithSessionKey(f func(r *http.Request) string) limiterOption

WithSessionKey return limiterOption. WithSessionKey config func which defines the request characteristic againstthe limit is applied

Types

type Limiter

type Limiter interface {
	// contains filtered or unexported methods
}

Limiter is an interface used to ratelimit

type RejectionResponse

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

RejectionResponse stores response information for the request rejected by limiter

Jump to

Keyboard shortcuts

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