Documentation ¶
Index ¶
Constants ¶
View Source
const ( // Header is Header = "X-Rate-Limit" // LocalRatelimitName is the name of the LocalRatelimit filter, which will be shown in log LocalRatelimitName = "localRatelimit" // DisableRatelimitName is the name of the DisableRatelimit, which will be shown in log DisableRatelimitName = "disableRatelimit" )
View Source
const ( DefaultMaxhits = 20 DefaultTimeWindow = 1 * time.Second DefaultCleanInterval = 60 * time.Second )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthLookuper ¶
type AuthLookuper struct{}
func NewAuthLookuper ¶
func NewAuthLookuper() AuthLookuper
type Lookuper ¶
type Lookuper interface { // Lookup is used to get the string which is used to define // how the bucket of a ratelimiter looks like, which is used // to decide to ratelimit or not. For example you can use the // X-Forwarded-For Header if you want to rate limit based on // source ip behind a proxy/loadbalancer or the Authorization // Header for request per token or user. Lookup(*http.Request) string }
Lookuper makes it possible to be more flexible for ratelimiting.
type Ratelimit ¶
type Ratelimit struct {
// contains filtered or unexported fields
}
Ratelimit is a proxy objects that delegates to implemetations and stores settings for the ratelimiter
type Registry ¶
Registry objects hold the active ratelimiters, ensure synchronized access to them, apply default settings and recycle the idle ratelimiters.
func NewRegistry ¶
NewRegistry initializes a registry with the provided default settings.
type Settings ¶
type Settings struct { Type Type Lookuper Lookuper Host string MaxHits int TimeWindow time.Duration CleanInterval time.Duration }
Settings configures the chosen rate limiter
type XForwardedForLookuper ¶
type XForwardedForLookuper struct{}
func NewXForwardedForLookuper ¶
func NewXForwardedForLookuper() XForwardedForLookuper
Click to show internal directories.
Click to hide internal directories.