Documentation
¶
Overview ¶
Package rate provides internal primitives used to build Redis-backed rate limit keys, errors, and limiter behavior for security-sensitive authentication workflows.
Window semantics ¶
Fixed-window counters: INCR + conditional EXPIRE on first hit. Key prefix:
- rl:login:fail:{tenant}:{identifier} — login failure counter
What this package must NOT do ¶
- Implement domain-specific policies (those live in internal/limiters).
- Be imported outside the goAuth module.
Index ¶
- Variables
- type Config
- type Limiter
- func (l *Limiter) CheckLogin(ctx context.Context, tenantID, identifier string) error
- func (l *Limiter) GetLoginAttempts(ctx context.Context, tenantID, identifier string) (int, error)
- func (l *Limiter) IncrementLogin(ctx context.Context, tenantID, identifier string) error
- func (l *Limiter) ResetLogin(ctx context.Context, tenantID, identifier string) error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrRateLimited is an exported constant or variable used by the authentication engine. ErrRateLimited = errors.New("rate limited") ErrRedisUnavailable = errors.New("redis unavailable") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
EnableLoginFailureLimiter bool
MaxLoginAttempts int
LoginCooldownDuration time.Duration
// WindowMode selects the counting algorithm (zero value = fixed window).
WindowMode window.Mode
}
Config holds rate limiter tuning parameters.
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
Limiter enforces identifier-scoped login failure limits using Redis counters.
func New ¶
func New(redisClient redis.UniversalClient, cfg Config) *Limiter
New creates a rate Limiter backed by the given Redis client.
func (*Limiter) CheckLogin ¶
CheckLogin checks whether the identifier is within the login attempt budget. Returns an error if rate-limited.
func (*Limiter) GetLoginAttempts ¶
GetLoginAttempts returns the current attempt counter for an identifier. Missing keys return zero and do not reveal account existence. In sliding mode this is the weighted count over the current window.
func (*Limiter) IncrementLogin ¶
IncrementLogin records a failed login attempt for the identifier.