Documentation ¶
Index ¶
- func NewLimiter(opts ...limiterOption) web.FilterFunc
- func NewTokenBucket(opts ...bucketOption) bucket
- func RemoteIPSessionKey(r *http.Request) string
- func WithBucketFactory(f func(opts ...bucketOption) bucket) limiterOption
- func WithCapacity(c uint) limiterOption
- func WithRate(r time.Duration) limiterOption
- func WithRejectionResponse(resp RejectionResponse) limiterOption
- func WithSessionKey(f func(r *http.Request) string) limiterOption
- type Limiter
- type RejectionResponse
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 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 ¶
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 ¶
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