Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetRateLimitHTTPHeaders ¶
func SetRateLimitHTTPHeaders(w http.ResponseWriter, res *Result)
SetRateLimitHTTPHeaders sets rate limit headers to the response.
Types ¶
type Config ¶
type Config struct {
Enable bool `yaml:"enable"`
StoreType string `yaml:"storeType"`
Redis *RedisStoreConfig `yaml:"redis"`
// Rate is allowed tokens for the period.
Rate int `yaml:"rate"`
// Period is the time period for the rate.
Period time.Duration `yaml:"period"`
// Burst is the maximum burst capacity.
Burst int `yaml:"burst"`
}
Config is the configuration for rate limiter.
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
Limiter is a rate limiter.
func NewLimiter ¶
NewLimiter returns a new rate limiter.
type RedisStoreConfig ¶
type RedisStoreConfig struct {
// host:port address.
Address string `yaml:"address"`
Username string `yaml:"username"`
Password string `yaml:"-"`
Database int `yaml:"database"`
}
RedisStoreConfig is the configuration for RedisStore.
type Result ¶
type Result struct {
// Allowed is true if the token is available.
Allowed bool
// Limit is the maximum number of tokens.
Limit int
// Remaining is the number of remaining tokens.
Remaining int
// RetryAfter is the duration until the next token becomes available.
RetryAfter time.Duration
// ResetAfter is the duration until the rate limit completely resets.
ResetAfter time.Duration
}
Result is the result of a Take call.
Click to show internal directories.
Click to hide internal directories.