postgres

package
v1.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 6 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package postgres provides a PostgreSQL-backed rate limit store.

Index

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 New

func New(db *pgxpool.Pool) *Store

New creates a new PostgreSQL rate limit store.

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

func (s *Store) Cleanup(ctx context.Context, olderThan time.Duration) (int64, error)

Cleanup removes expired rate limit records. This can be called periodically to prevent the table from growing indefinitely.

func (*Store) Get

func (s *Store) Get(ctx context.Context, key string) (*ratelimit.Result, error)

Get retrieves the current rate limit state for a key without incrementing. Returns nil if no rate limit exists for the key.

func (*Store) Reset

func (s *Store) Reset(ctx context.Context, key string) error

Reset implements ratelimit.Store.Reset by deleting the rate limit record.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL