limiter

package
v4.0.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2019 License: MIT Imports: 5 Imported by: 0

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
	ExpireJobInterval time.Duration
}

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) 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) 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) GetMax

func (l *Limiter) GetMax() float64

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

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) 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) 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 adding 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) 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) SetMax

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

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

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) 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