limiter

package
v6.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2022 License: MIT Imports: 5 Imported by: 36

Documentation

Overview

Package limiter 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 ExpirableOptions

type ExpirableOptions struct {
	DefaultExpirationTTL time.Duration

	// How frequently expire job triggers
	// Deprecated: not used anymore
	ExpireJobInterval time.Duration
}

ExpirableOptions are options used for new limiter creation

type Limiter

type Limiter struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

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) DeleteExpiredTokenBuckets added in v6.1.2

func (l *Limiter) DeleteExpiredTokenBuckets()

DeleteExpiredTokenBuckets is thread-safe way of deleting expired token buckets

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

func (l *Limiter) GetBasicAuthExpirationTTL() time.Duration

GetBasicAuthExpirationTTL is thread-safe way of getting custom basic auth expiration TTL.

func (*Limiter) GetBasicAuthUsers

func (l *Limiter) GetBasicAuthUsers() []string

GetBasicAuthUsers is thread-safe way of getting list of basic auth usernames to limit.

func (*Limiter) GetBurst

func (l *Limiter) GetBurst() int

GetBurst is thread-safe way of setting maximum burst size.

func (*Limiter) GetContextValue

func (l *Limiter) GetContextValue(contextValue string) []string

GetContextValue is thread-safe way of getting 1 Context value entry.

func (*Limiter) GetContextValueEntryExpirationTTL

func (l *Limiter) GetContextValueEntryExpirationTTL() time.Duration

GetContextValueEntryExpirationTTL is thread-safe way of getting custom Context value expiration TTL.

func (*Limiter) GetContextValues

func (l *Limiter) GetContextValues() map[string][]string

GetContextValues is thread-safe way of getting a map of Context values to limit.

func (*Limiter) GetForwardedForIndexFromBehind

func (l *Limiter) GetForwardedForIndexFromBehind() int

GetForwardedForIndexFromBehind is thread-safe way of getting which X-Forwarded-For index to choose.

func (*Limiter) GetHeader

func (l *Limiter) GetHeader(header string) []string

GetHeader is thread-safe way of getting entries of 1 HTTP header.

func (*Limiter) GetHeaderEntryExpirationTTL

func (l *Limiter) GetHeaderEntryExpirationTTL() time.Duration

GetHeaderEntryExpirationTTL is thread-safe way of getting custom basic auth expiration TTL.

func (*Limiter) GetHeaders

func (l *Limiter) GetHeaders() map[string][]string

GetHeaders is thread-safe way of getting map of HTTP headers to limit.

func (*Limiter) GetIPLookups

func (l *Limiter) GetIPLookups() []string

GetIPLookups is thread-safe way of getting list of places to look up IP address.

func (*Limiter) GetIgnoreURL added in v6.1.1

func (l *Limiter) GetIgnoreURL() bool

GetIgnoreURL returns whether the URL is ignored in the rate limit key set

func (*Limiter) GetMax

func (l *Limiter) GetMax() float64

GetMax is thread-safe way of getting maximum number of requests to limit per second.

func (*Limiter) GetMessage

func (l *Limiter) GetMessage() string

GetMessage is thread-safe way of getting HTTP message when limit is reached.

func (*Limiter) GetMessageContentType

func (l *Limiter) GetMessageContentType() string

GetMessageContentType is thread-safe way of getting HTTP message Content-Type when limit is reached.

func (*Limiter) GetMethods

func (l *Limiter) GetMethods() []string

GetMethods is thread-safe way of getting list of HTTP Methods to limit (GET, POST, PUT, etc.).

func (*Limiter) GetOverrideDefaultResponseWriter added in v6.0.2

func (l *Limiter) GetOverrideDefaultResponseWriter() bool

GetOverrideDefaultResponseWriter is a thread-safe way of getting the response writer override variable.

func (*Limiter) GetStatusCode

func (l *Limiter) GetStatusCode() int

GetStatusCode is thread-safe way of getting HTTP status code when limit is reached.

func (*Limiter) GetTokenBucketExpirationTTL

func (l *Limiter) GetTokenBucketExpirationTTL() time.Duration

GetTokenBucketExpirationTTL is thread-safe way of getting custom token bucket expiration TTL.

func (*Limiter) LimitReached

func (l *Limiter) LimitReached(key string) bool

LimitReached returns a bool indicating if the Bucket identified by key ran out of tokens.

func (*Limiter) RemoveBasicAuthUsers

func (l *Limiter) RemoveBasicAuthUsers(basicAuthUsers []string) *Limiter

RemoveBasicAuthUsers is thread-safe way of removing basic auth usernames from existing list.

func (*Limiter) RemoveContextValue

func (l *Limiter) RemoveContextValue(contextValue string) *Limiter

RemoveContextValue is thread-safe way of removing entries of 1 Context value.

func (*Limiter) RemoveContextValuesEntries

func (l *Limiter) RemoveContextValuesEntries(contextValue string, entriesForRemoval []string) *Limiter

RemoveContextValuesEntries is thread-safe way of removing entries to a ContextValue.

func (*Limiter) RemoveHeader

func (l *Limiter) RemoveHeader(header string) *Limiter

RemoveHeader is thread-safe way of removing entries of 1 HTTP header.

func (*Limiter) RemoveHeaderEntries

func (l *Limiter) RemoveHeaderEntries(header string, entriesForRemoval []string) *Limiter

RemoveHeaderEntries is thread-safe way of removing new entries to 1 HTTP header rule.

func (*Limiter) SetBasicAuthExpirationTTL

func (l *Limiter) SetBasicAuthExpirationTTL(ttl time.Duration) *Limiter

SetBasicAuthExpirationTTL is thread-safe way of setting custom basic auth expiration TTL.

func (*Limiter) SetBasicAuthUsers

func (l *Limiter) SetBasicAuthUsers(basicAuthUsers []string) *Limiter

SetBasicAuthUsers is thread-safe way of setting list of basic auth usernames to limit.

func (*Limiter) SetBurst

func (l *Limiter) SetBurst(burst int) *Limiter

SetBurst is thread-safe way of setting maximum burst size.

func (*Limiter) SetContextValue

func (l *Limiter) SetContextValue(contextValue string, entries []string) *Limiter

SetContextValue is thread-safe way of setting entries of 1 Context value.

func (*Limiter) SetContextValueEntryExpirationTTL

func (l *Limiter) SetContextValueEntryExpirationTTL(ttl time.Duration) *Limiter

SetContextValueEntryExpirationTTL is thread-safe way of setting custom Context value expiration TTL.

func (*Limiter) SetContextValues

func (l *Limiter) SetContextValues(contextValues map[string][]string) *Limiter

SetContextValues is thread-safe way of setting map of HTTP headers to limit.

func (*Limiter) SetForwardedForIndexFromBehind

func (l *Limiter) SetForwardedForIndexFromBehind(forwardedForIndex int) *Limiter

SetForwardedForIndexFromBehind is thread-safe way of setting which X-Forwarded-For index to choose.

func (*Limiter) SetHeader

func (l *Limiter) SetHeader(header string, entries []string) *Limiter

SetHeader is thread-safe way of setting entries of 1 HTTP header.

func (*Limiter) SetHeaderEntryExpirationTTL

func (l *Limiter) SetHeaderEntryExpirationTTL(ttl time.Duration) *Limiter

SetHeaderEntryExpirationTTL is thread-safe way of setting custom basic auth expiration TTL.

func (*Limiter) SetHeaders

func (l *Limiter) SetHeaders(headers map[string][]string) *Limiter

SetHeaders is thread-safe way of setting map of HTTP headers to limit.

func (*Limiter) SetIPLookups

func (l *Limiter) SetIPLookups(ipLookups []string) *Limiter

SetIPLookups is thread-safe way of setting list of places to look up IP address.

func (*Limiter) SetIgnoreURL added in v6.1.1

func (l *Limiter) SetIgnoreURL(enabled bool) *Limiter

SetIgnoreURL is thread-safe way of setting whenever ignore the URL on rate limit keys

func (*Limiter) SetMax

func (l *Limiter) SetMax(max float64) *Limiter

SetMax is thread-safe way of setting maximum number of requests to limit per second.

func (*Limiter) SetMessage

func (l *Limiter) SetMessage(msg string) *Limiter

SetMessage is thread-safe way of setting HTTP message when limit is reached.

func (*Limiter) SetMessageContentType

func (l *Limiter) SetMessageContentType(contentType string) *Limiter

SetMessageContentType is thread-safe way of setting HTTP message Content-Type when limit is reached.

func (*Limiter) SetMethods

func (l *Limiter) SetMethods(methods []string) *Limiter

SetMethods is thread-safe way of setting list of HTTP Methods to limit (GET, POST, PUT, etc.).

func (*Limiter) SetOnLimitReached

func (l *Limiter) SetOnLimitReached(fn func(w http.ResponseWriter, r *http.Request)) *Limiter

SetOnLimitReached is thread-safe way of setting after-rejection function when limit is reached.

func (*Limiter) SetOverrideDefaultResponseWriter added in v6.0.2

func (l *Limiter) SetOverrideDefaultResponseWriter(override bool)

SetOverrideDefaultResponseWriter is a thread-safe way of setting the response writer override variable.

func (*Limiter) SetStatusCode

func (l *Limiter) SetStatusCode(statusCode int) *Limiter

SetStatusCode is thread-safe way of setting HTTP status code when limit is reached.

func (*Limiter) SetTokenBucketExpirationTTL

func (l *Limiter) SetTokenBucketExpirationTTL(ttl time.Duration) *Limiter

SetTokenBucketExpirationTTL is thread-safe way of setting custom token bucket expiration TTL.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL