Documentation ¶
Overview ¶
Package limiter provides data structure to configure rate-limiter.
Index ¶
- type ExpirableOptions
- type Limiter
- func (l *Limiter) ExecOnLimitReached(w http.ResponseWriter, r *http.Request)
- func (l *Limiter) GetBasicAuthExpirationTTL() time.Duration
- func (l *Limiter) GetBasicAuthUsers() []string
- func (l *Limiter) GetBurst() int
- func (l *Limiter) GetForwardedForIndexFromBehind() int
- func (l *Limiter) GetHeader(header string) []string
- func (l *Limiter) GetHeaderEntryExpirationTTL() time.Duration
- func (l *Limiter) GetHeaders() map[string][]string
- func (l *Limiter) GetIPLookups() []string
- func (l *Limiter) GetMax() int64
- func (l *Limiter) GetMessage() string
- func (l *Limiter) GetMessageContentType() string
- func (l *Limiter) GetMethods() []string
- func (l *Limiter) GetStatusCode() int
- func (l *Limiter) GetTokenBucketExpirationTTL() time.Duration
- func (l *Limiter) LimitReached(key string) bool
- func (l *Limiter) RemoveBasicAuthUsers(basicAuthUsers []string) *Limiter
- func (l *Limiter) RemoveHeader(header string) *Limiter
- func (l *Limiter) RemoveHeaderEntries(header string, entriesForRemoval []string) *Limiter
- func (l *Limiter) SetBasicAuthExpirationTTL(ttl time.Duration) *Limiter
- func (l *Limiter) SetBasicAuthUsers(basicAuthUsers []string) *Limiter
- func (l *Limiter) SetBurst(burst int) *Limiter
- func (l *Limiter) SetForwardedForIndexFromBehind(forwardedForIndex int) *Limiter
- func (l *Limiter) SetHeader(header string, entries []string) *Limiter
- func (l *Limiter) SetHeaderEntryExpirationTTL(ttl time.Duration) *Limiter
- func (l *Limiter) SetHeaders(headers map[string][]string) *Limiter
- func (l *Limiter) SetIPLookups(ipLookups []string) *Limiter
- func (l *Limiter) SetMax(max int64) *Limiter
- func (l *Limiter) SetMessage(msg string) *Limiter
- func (l *Limiter) SetMessageContentType(contentType string) *Limiter
- func (l *Limiter) SetMethods(methods []string) *Limiter
- func (l *Limiter) SetOnLimitReached(fn func(w http.ResponseWriter, r *http.Request)) *Limiter
- func (l *Limiter) SetStatusCode(statusCode int) *Limiter
- func (l *Limiter) SetTokenBucketExpirationTTL(ttl time.Duration) *Limiter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ExpirableOptions ¶
type Limiter ¶
Limiter is a config struct to limit a particular request handler.
func New ¶
func New(generalExpirableOptions *ExpirableOptions) *Limiter
New is a constructor for Limiter.
func (*Limiter) ExecOnLimitReached ¶
func (l *Limiter) ExecOnLimitReached(w http.ResponseWriter, r *http.Request)
ExecOnLimitReached is thread-safe way of executing after-rejection function when limit is reached.
func (*Limiter) GetBasicAuthExpirationTTL ¶
GetBasicAuthExpirationTTL is thread-safe way of getting custom basic auth expiration TTL.
func (*Limiter) GetBasicAuthUsers ¶
GetBasicAuthUsers is thread-safe way of getting list of basic auth usernames to limit.
func (*Limiter) GetBurst ¶ added in v3.0.1
GetBurst is thread-safe way of setting maximum burst size.
func (*Limiter) GetForwardedForIndexFromBehind ¶
GetForwardedForIndexFromBehind is thread-safe way of getting which X-Forwarded-For index to choose.
func (*Limiter) GetHeaderEntryExpirationTTL ¶
GetHeaderEntryExpirationTTL is thread-safe way of getting custom basic auth expiration TTL.
func (*Limiter) GetHeaders ¶
GetHeaders is thread-safe way of getting map of HTTP headers to limit.
func (*Limiter) GetIPLookups ¶
GetIPLookups is thread-safe way of getting list of places to look up IP address.
func (*Limiter) GetMax ¶
GetMax is thread-safe way of getting maximum number of requests to limit per duration.
func (*Limiter) GetMessage ¶
GetMessage is thread-safe way of getting HTTP message when limit is reached.
func (*Limiter) GetMessageContentType ¶
GetMessageContentType is thread-safe way of getting HTTP message Content-Type when limit is reached.
func (*Limiter) GetMethods ¶
GetMethods is thread-safe way of getting list of HTTP Methods to limit (GET, POST, PUT, etc.).
func (*Limiter) GetStatusCode ¶
GetStatusCode is thread-safe way of getting HTTP status code when limit is reached.
func (*Limiter) GetTokenBucketExpirationTTL ¶
GettokenBucketExpirationTTL is thread-safe way of getting custom token bucket expiration TTL.
func (*Limiter) LimitReached ¶
LimitReached returns a bool indicating if the Bucket identified by key ran out of tokens.
func (*Limiter) RemoveBasicAuthUsers ¶
RemoveBasicAuthUsers is thread-safe way of removing basic auth usernames from existing list.
func (*Limiter) RemoveHeader ¶
RemoveHeader is thread-safe way of removing entries of 1 HTTP header.
func (*Limiter) RemoveHeaderEntries ¶
RemoveHeaderEntries is thread-safe way of adding new entries to 1 HTTP header rule.
func (*Limiter) SetBasicAuthExpirationTTL ¶
SetBasicAuthExpirationTTL is thread-safe way of setting custom basic auth expiration TTL.
func (*Limiter) SetBasicAuthUsers ¶
SetBasicAuthUsers is thread-safe way of setting list of basic auth usernames to limit.
func (*Limiter) SetBurst ¶ added in v3.0.1
SetBurst is thread-safe way of setting maximum burst size.
func (*Limiter) SetForwardedForIndexFromBehind ¶
SetForwardedForIndexFromBehind is thread-safe way of setting which X-Forwarded-For index to choose.
func (*Limiter) SetHeaderEntryExpirationTTL ¶
SetHeaderEntryExpirationTTL is thread-safe way of setting custom basic auth expiration TTL.
func (*Limiter) SetHeaders ¶
SetHeaders is thread-safe way of setting map of HTTP headers to limit.
func (*Limiter) SetIPLookups ¶
SetIPLookups is thread-safe way of setting list of places to look up IP address.
func (*Limiter) SetMax ¶
SetMax is thread-safe way of setting maximum number of requests to limit per duration.
func (*Limiter) SetMessage ¶
SetMessage is thread-safe way of setting HTTP message when limit is reached.
func (*Limiter) SetMessageContentType ¶
SetMessageContentType is thread-safe way of setting HTTP message Content-Type when limit is reached.
func (*Limiter) SetMethods ¶
SetMethods is thread-safe way of setting list of HTTP Methods to limit (GET, POST, PUT, etc.).
func (*Limiter) SetOnLimitReached ¶
SetOnLimitReached is thread-safe way of setting after-rejection function when limit is reached.
func (*Limiter) SetStatusCode ¶
SetStatusCode is thread-safe way of setting HTTP status code when limit is reached.