sqlitedriver

package module
v0.0.0-...-058c7cc Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultPruneInterval = 1 * time.Minute

Variables

This section is empty.

Functions

func WithLogger

func WithLogger(logger *slog.Logger) func(d *Driver)

WithLogger sets the logger. When not specified, uses slog.Default.

func WithPruneInterval

func WithPruneInterval(interval time.Duration) func(d *Driver)

WithPruneInterval sets the expired challenge prune interval. When not specified, uses DefaultPruneInterval.

func WithRateLimit

func WithRateLimit(opts ...func(rl *cap.RateLimitOptions)) func(d *Driver)

WithRateLimit enables rate limiting and uses the specified options for it.

Types

type Driver

type Driver struct {
	// contains filtered or unexported fields
}

Driver is the SQLite driver for Cap. It stores challenges in an SQLite database, and optionally uses it for rate limiting.

Note that the DB used to create the Driver will be closed when Driver.Close is called. The DB should be in WAL mode for ideal performance.

Rate limiting is supported if enabled, and uses a sliding window algorithm.

func NewDriver

func NewDriver(sqlite *sql.DB, opts ...func(d *Driver)) (*Driver, error)

NewDriver creates a new SQLite driver with the specified DB and options. Note that the DB passed in will be closed when Driver.Close is called.

func (*Driver) Close

func (d *Driver) Close() error

func (*Driver) GetUnredeemedChallenge

func (d *Driver) GetUnredeemedChallenge(ctx context.Context, challengeToken string) (*cap.Challenge, error)

func (*Driver) Store

func (d *Driver) Store(ctx context.Context, challenge *cap.Challenge, ip *netip.Addr) error

func (*Driver) UseRedeemToken

func (d *Driver) UseRedeemToken(ctx context.Context, redeemToken string) (wasRedeemed bool, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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