Documentation
¶
Index ¶
- Variables
- type Config
- type EchoConfig
- type FiberConfig
- type GinConfig
- type Limiter
- func (l *Limiter) Close() error
- func (l *Limiter) EchoMiddleware(cfg EchoConfig) echo.MiddlewareFunc
- func (l *Limiter) FiberMiddleware(cfg FiberConfig) fiber.Handler
- func (l *Limiter) GinMiddleware(cfg GinConfig) gin.HandlerFunc
- func (l *Limiter) StdLibMiddleware(cfg StdLibConfig) func(http.Handler) http.Handler
- type MemoryEntries
- type MemoryStore
- func (m *MemoryStore) Close() error
- func (m *MemoryStore) Get(ctx context.Context, key string) (int, error)
- func (m *MemoryStore) Rollback(ctx context.Context, key string) error
- func (m *MemoryStore) Set(ctx context.Context, key string, value int, expiration time.Duration) error
- func (m *MemoryStore) Take(ctx context.Context, key string, maxRequests int, window time.Duration, ...) (bool, int, time.Time, error)
- type RedisStore
- func (r *RedisStore) Close() error
- func (r *RedisStore) Get(ctx context.Context, key string) (int, error)
- func (r *RedisStore) Rollback(ctx context.Context, key string) error
- func (r *RedisStore) Set(ctx context.Context, key string, value int, expiration time.Duration) error
- func (r *RedisStore) Take(ctx context.Context, key string, maxRequests int, window time.Duration, ...) (bool, int, time.Time, error)
- type StdLibConfig
- type Store
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Redis Configuration for starting limiter
RedisClient *redis.Client
RedisURL string
// Rate Limiter configuration
MaxRequests int
Window time.Duration
// value "token-bucket", "sliding-window" and "fixed-window"
Algorithm string
}
Config holds the core configuration for the rate limiter. Framework-specific settings are handled in their respective middleware generators.
type EchoConfig ¶ added in v2.0.6
type FiberConfig ¶ added in v2.0.6
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
func (*Limiter) EchoMiddleware ¶ added in v2.0.6
func (l *Limiter) EchoMiddleware(cfg EchoConfig) echo.MiddlewareFunc
func (*Limiter) FiberMiddleware ¶ added in v2.0.6
func (l *Limiter) FiberMiddleware(cfg FiberConfig) fiber.Handler
func (*Limiter) GinMiddleware ¶ added in v2.0.6
func (l *Limiter) GinMiddleware(cfg GinConfig) gin.HandlerFunc
func (*Limiter) StdLibMiddleware ¶ added in v2.0.6
StdLibMiddleware creates a standard net/http middleware. This works for Chi, Go Standard Library, and any framework compatible with http.Handler.
type MemoryEntries ¶
type MemoryEntries struct {
// contains filtered or unexported fields
}
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
func NewMemoryStore ¶
func NewMemoryStore() *MemoryStore
func (*MemoryStore) Close ¶
func (m *MemoryStore) Close() error
func (*MemoryStore) Rollback ¶
func (m *MemoryStore) Rollback(ctx context.Context, key string) error
type RedisStore ¶
type RedisStore struct {
// contains filtered or unexported fields
}
func NewRedisStore ¶
func NewRedisStore(client *redis.Client) *RedisStore
func (*RedisStore) Close ¶
func (r *RedisStore) Close() error
type StdLibConfig ¶ added in v2.0.6
type Store ¶
type Store interface {
Take(ctx context.Context, key string, maxRequests int, window time.Duration, algorithm string) (bool, int, time.Time, error)
Rollback(ctx context.Context, key string) error
Get(ctx context.Context, key string) (int, error)
Set(ctx context.Context, key string, value int, expiration time.Duration) error
}
Store defines the interface for limiter Store have 4 values Take, Rollback, Get and Set
Click to show internal directories.
Click to hide internal directories.