Help us shape the future of Go! Take the 2026 Go Developer Survey

ratelimit

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AllowResult

type AllowResult struct {
	Allow     bool
	Limit     uint64
	Remaining uint64
	ResetTime time.Time
}

type Limiter

type Limiter interface {
	Allow(ctx context.Context, key string) *AllowResult
}

type LocalAsyncRedisLimiter

type LocalAsyncRedisLimiter struct {
	// contains filtered or unexported fields
}

func NewLocalAsyncRedisLimiter

func NewLocalAsyncRedisLimiter(client redis.UniversalClient, options Options) *LocalAsyncRedisLimiter

func (*LocalAsyncRedisLimiter) TryAcquire

func (r *LocalAsyncRedisLimiter) TryAcquire(token int64) bool

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"`
	HTTPStatusCode   int           `mapstructure:"http_status_code"`
	HTTPContentType  string        `mapstructure:"http_content_type"`
	HTTPResponseBody string        `mapstructure:"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

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
)

Jump to

Keyboard shortcuts

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