Versions in this module Expand all Collapse all v0 v0.0.1 Dec 15, 2025 Changes in this version + func Middleware(config MiddlewareConfig) ghttp.HandlerFunc + func MiddlewareByAPIKey(limiter Limiter, keyHeader string) ghttp.HandlerFunc + func MiddlewareByIP(limiter Limiter) ghttp.HandlerFunc + func MiddlewareByUser(limiter Limiter, userFunc func(r *ghttp.Request) string) ghttp.HandlerFunc + type Limiter interface + Allow func(ctx context.Context, key string) (bool, error) + AllowN func(ctx context.Context, key string, n int) (bool, error) + GetLimit func() int + GetRemaining func(ctx context.Context, key string) (int, error) + GetResetTime func(ctx context.Context, key string) (time.Time, error) + GetWindow func() time.Duration + Reset func(ctx context.Context, key string) error + Wait func(ctx context.Context, key string) error + type MemoryLimiter struct + func NewMemoryLimiter(limit int, window time.Duration) *MemoryLimiter + func (l *MemoryLimiter) Allow(ctx context.Context, key string) (bool, error) + func (l *MemoryLimiter) AllowN(ctx context.Context, key string, n int) (bool, error) + func (l *MemoryLimiter) GetLimit() int + func (l *MemoryLimiter) GetRemaining(ctx context.Context, key string) (int, error) + func (l *MemoryLimiter) GetResetTime(ctx context.Context, key string) (time.Time, error) + func (l *MemoryLimiter) GetWindow() time.Duration + func (l *MemoryLimiter) Reset(ctx context.Context, key string) error + func (l *MemoryLimiter) Wait(ctx context.Context, key string) error + type MiddlewareConfig struct + ErrorHandler func(r *ghttp.Request) + KeyFunc func(r *ghttp.Request) string + Limiter Limiter + type RedisLimiter struct + func NewRedisLimiter(redis *gredis.Redis, limit int, window time.Duration) *RedisLimiter + func (l *RedisLimiter) Allow(ctx context.Context, key string) (bool, error) + func (l *RedisLimiter) AllowN(ctx context.Context, key string, n int) (bool, error) + func (l *RedisLimiter) GetLimit() int + func (l *RedisLimiter) GetRemaining(ctx context.Context, key string) (int, error) + func (l *RedisLimiter) GetResetTime(ctx context.Context, key string) (time.Time, error) + func (l *RedisLimiter) GetWindow() time.Duration + func (l *RedisLimiter) Reset(ctx context.Context, key string) error + func (l *RedisLimiter) Wait(ctx context.Context, key string) error