Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DatabaseStorageConfig ¶
type MemoryStorageConfig ¶
type RateLimitCheckRequest ¶
RateLimitCheckRequest contains the information needed to check rate limits
type RateLimitCheckResponse ¶
type RateLimitCheckResponse struct {
// Allowed indicates whether the request should be allowed
Allowed bool
// Limit is the maximum number of requests allowed
Limit int
// Window is the time window for the rate limit in seconds
Window int
// RetryAfter is the number of seconds to wait before retrying (only set if Allowed is false)
RetryAfter int
}
RateLimitCheckResponse contains the result of a rate limit check
type RateLimitEntry ¶
RateLimitEntry tracks requests for a specific key
type RateLimitPluginConfig ¶
type RateLimitPluginConfig struct {
Enabled bool `json:"enabled" toml:"enabled"`
Window time.Duration `json:"window" toml:"window"`
Max int `json:"max" toml:"max"`
Prefix string `json:"prefix,omitempty" toml:"prefix"`
CustomRules map[string]RateLimitRule `json:"custom_rules" toml:"custom_rules"`
Provider RateLimitProviderType `json:"provider" toml:"provider"`
Memory *MemoryStorageConfig `json:"memory,omitempty" toml:"memory"`
Database *DatabaseStorageConfig `json:"database,omitempty" toml:"database"`
}
func (*RateLimitPluginConfig) ApplyDefaults ¶
func (config *RateLimitPluginConfig) ApplyDefaults()
type RateLimitProvider ¶
type RateLimitProvider interface {
// GetName returns the name of the provider
GetName() string
// CheckAndIncrement checks if a request is allowed and increments the counter if so
// key is the fully-qualified key (with prefix already included)
// window is the time window for expiration
// maxRequests is the maximum number of requests allowed in the window
// Returns: (allowed bool, currentCount int, resetTime time.Time, error)
CheckAndIncrement(ctx context.Context, key string, window time.Duration, maxRequests int) (bool, int, time.Time, error)
// SetRule stores a per-key rate-limit rule without consuming quota.
SetRule(ctx context.Context, key string, window time.Duration, maxRequests int) error
// GetRule retrieves a stored per-key rule. Returns 0, 0, false, nil when not found.
GetRule(ctx context.Context, key string) (window time.Duration, maxRequests int, found bool, err error)
// DeleteRule removes the stored rule for a key.
DeleteRule(ctx context.Context, key string) error
// Close closes any resources held by the provider
Close() error
}
RateLimitProvider defines the interface for rate limit storage backends Implementations can use in-memory storage, Redis, database, or any other backend
type RateLimitProviderType ¶
type RateLimitProviderType string
const ( RateLimitProviderInMemory RateLimitProviderType = "memory" RateLimitProviderRedis RateLimitProviderType = "redis" RateLimitProviderDatabase RateLimitProviderType = "database" )
func (RateLimitProviderType) String ¶
func (r RateLimitProviderType) String() string
type RateLimitRule ¶
Click to show internal directories.
Click to hide internal directories.