Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PutAllowResult ¶ added in v0.4.0
func PutAllowResult(result *AllowResult)
PutAllowResult returns an AllowResult to the pool
Types ¶
type AllowResult ¶
func GetAllowResult ¶ added in v0.4.0
func GetAllowResult() *AllowResult
GetAllowResult gets an AllowResult from the pool
type LocalLimiter ¶
type LocalLimiter struct {
// contains filtered or unexported fields
}
func NewLocalLimiter ¶
func NewLocalLimiter(options Options) *LocalLimiter
func (*LocalLimiter) Allow ¶
func (l *LocalLimiter) Allow(ctx context.Context, key string) *AllowResult
type Options ¶
type Options struct {
Strategy StrategyMode `mapstructure:"strategy"`
Limit uint64 `mapstructure:"limit"`
LimitBy string `mapstructure:"limit_by"`
WindowSize time.Duration `mapstructure:"window_size"`
HeaderLimit string `mapstructure:"header_limit"`
HeaderRemaining string `mapstructure:"header_remaining"`
HeaderReset string `mapstructure:"header_reset"`
RejectedHTTPStatusCode int `mapstructure:"rejected_http_status_code"`
RejectedHTTPContentType string `mapstructure:"rejected_http_content_type"`
RejectedHTTPResponseBody string `mapstructure:"rejected_http_response_body"`
RedisID string `mapstructure:"redis_id"`
}
type RateLimitingMiddleware ¶
type RateLimitingMiddleware struct {
// contains filtered or unexported fields
}
func NewMiddleware ¶
func NewMiddleware(options Options) (*RateLimitingMiddleware, error)
func (*RateLimitingMiddleware) ServeHTTP ¶
func (m *RateLimitingMiddleware) ServeHTTP(ctx context.Context, c *app.RequestContext)
type RedisLimiter ¶
type RedisLimiter struct {
// contains filtered or unexported fields
}
func NewRedisLimiter ¶
func NewRedisLimiter(client redis.UniversalClient, options Options) *RedisLimiter
func (*RedisLimiter) Allow ¶
func (l *RedisLimiter) Allow(ctx context.Context, key string) *AllowResult
type StrategyMode ¶
type StrategyMode string
const ( Local StrategyMode = "local" Redis StrategyMode = "redis" LocalAsyncRedis StrategyMode = "local_async_redis" // nolint )
Click to show internal directories.
Click to hide internal directories.