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) GetContextValue(contextValue string) []string
- func (l *Limiter) GetContextValueEntryExpirationTTL() time.Duration
- func (l *Limiter) GetContextValues() map[string][]string
- 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() float64
- 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) RemoveContextValue(contextValue string) *Limiter
- func (l *Limiter) RemoveContextValuesEntries(contextValue string, entriesForRemoval []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) SetContextValue(contextValue string, entries []string) *Limiter
- func (l *Limiter) SetContextValueEntryExpirationTTL(ttl time.Duration) *Limiter
- func (l *Limiter) SetContextValues(contextValues map[string][]string) *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 float64) *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 ExpirableOptions struct { DefaultExpirationTTL time.Duration // How frequently expire job triggers ExpireJobInterval time.Duration }
ExpirableOptions are options used for new limiter creation
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) GetContextValue ¶ added in v5.1.1
GetContextValue is thread-safe way of getting 1 Context value entry.
func (*Limiter) GetContextValueEntryExpirationTTL ¶ added in v5.1.1
GetContextValueEntryExpirationTTL is thread-safe way of getting custom Context value expiration TTL.
func (*Limiter) GetContextValues ¶ added in v5.1.1
GetContextValues is thread-safe way of getting a map of Context values to limit.
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 second.
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) RemoveContextValue ¶ added in v5.1.1
RemoveContextValue is thread-safe way of removing entries of 1 Context value.
func (*Limiter) RemoveContextValuesEntries ¶ added in v5.1.1
func (l *Limiter) RemoveContextValuesEntries(contextValue string, entriesForRemoval []string) *Limiter
RemoveContextValuesEntries is thread-safe way of removing entries to a ContextValue.
func (*Limiter) RemoveHeader ¶
RemoveHeader is thread-safe way of removing entries of 1 HTTP header.
func (*Limiter) RemoveHeaderEntries ¶
RemoveHeaderEntries is thread-safe way of removing 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) SetContextValue ¶ added in v5.1.1
SetContextValue is thread-safe way of setting entries of 1 Context value.
func (*Limiter) SetContextValueEntryExpirationTTL ¶ added in v5.1.1
SetContextValueEntryExpirationTTL is thread-safe way of setting custom Context value expiration TTL.
func (*Limiter) SetContextValues ¶ added in v5.1.1
SetContextValues is thread-safe way of setting map of HTTP headers to limit.
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 second.
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.