ratelimit

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2024 License: Apache-2.0, Apache-2.0 Imports: 4 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 RemoteIPSessionKey

func RemoteIPSessionKey(ctx *context.Context) 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(ctx *context.Context) string) limiterOption

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

Types

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