Documentation
¶
Overview ¶
Package postgres provides a PostgreSQL-backed rate limit store.
Index ¶
- type Store
- func (s *Store) Check(ctx context.Context, key string, limit int, window time.Duration) (ratelimit.Result, error)
- func (s *Store) Cleanup(ctx context.Context, olderThan time.Duration) (int64, error)
- func (s *Store) Get(ctx context.Context, key string) (*ratelimit.Result, error)
- func (s *Store) Reset(ctx context.Context, key string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store implements ratelimit.Store using PostgreSQL with a fixed-window algorithm.
func (*Store) Check ¶
func (s *Store) Check(ctx context.Context, key string, limit int, window time.Duration) (ratelimit.Result, error)
Check implements ratelimit.Store.Check using a fixed-window algorithm.
Algorithm: 1. If no record exists OR window has expired, create/reset with counter=1 2. If window is active and counter < max, increment and allow 3. If window is active and counter >= max, deny
func (*Store) Cleanup ¶
Cleanup removes expired rate limit records. This can be called periodically to prevent the table from growing indefinitely.
Click to show internal directories.
Click to hide internal directories.