Documentation
¶
Index ¶
- Constants
- func WithLogger(logger *slog.Logger) func(d *Driver)
- func WithPruneInterval(interval time.Duration) func(d *Driver)
- func WithRateLimit(opts ...func(rl *cap.RateLimitOptions)) func(d *Driver)
- type Driver
- func (d *Driver) Close() error
- func (d *Driver) GetUnredeemedChallenge(ctx context.Context, challengeToken string) (*cap.Challenge, error)
- func (d *Driver) Store(ctx context.Context, challenge *cap.Challenge, ip *netip.Addr) error
- func (d *Driver) UseRedeemToken(ctx context.Context, redeemToken string) (wasRedeemed bool, err error)
Constants ¶
const DefaultPruneInterval = 1 * time.Minute
Variables ¶
This section is empty.
Functions ¶
func WithLogger ¶
WithLogger sets the logger. When not specified, uses slog.Default.
func WithPruneInterval ¶
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 ¶
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.