Documentation ¶
Overview ¶
Package config provides data structure to configure rate-limiter.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Limiter ¶
type Limiter struct { // HTTP message when limit is reached. Message string // Content-Type for Message MessageContentType string // HTTP status code when limit is reached. StatusCode int // Maximum number of requests to limit per duration. Max int64 // Duration of rate-limiter. TTL time.Duration // List of places to look up IP address. // Default is "RemoteAddr", "X-Forwarded-For", "X-Real-IP". // You can rearrange the order as you like. IPLookups []string // A function to call when a request is rejected. RejectFunc func() // List of HTTP Methods to limit (GET, POST, PUT, etc.). // Empty means limit all methods. Methods []string // List of HTTP headers to limit. // Empty means skip headers checking. Headers map[string][]string // List of basic auth usernames to limit. BasicAuthUsers []string // Able to configure token bucket expirations. TokenBuckets struct { // Default TTL to expire bucket per key basis. DefaultExpirationTTL time.Duration // How frequently tollbooth will trigger the expire job ExpireJobInterval time.Duration } sync.RWMutex // contains filtered or unexported fields }
Limiter is a config struct to limit a particular request handler.
func NewLimiter ¶
NewLimiter is a constructor for Limiter.
func NewLimiterExpiringBuckets ¶
func NewLimiterExpiringBuckets(max int64, ttl, bucketDefaultExpirationTTL, bucketExpireJobInterval time.Duration) *Limiter
NewLimiterExpiringBuckets constructs Limiter with expirable TokenBuckets.
func (*Limiter) LimitReached ¶
LimitReached returns a bool indicating if the Bucket identified by key ran out of tokens.
func (*Limiter) LimitReachedWithCustomTokenBucketTTL ¶
func (l *Limiter) LimitReachedWithCustomTokenBucketTTL(key string, tokenBucketTTL time.Duration) bool
LimitReachedWithCustomTokenBucketTTL returns a bool indicating if the Bucket identified by key ran out of tokens. This public API allows user to define custom expiration TTL on the key.
Click to show internal directories.
Click to hide internal directories.