Documentation
¶
Overview ¶
Package certmagicsqlite provides a SQLite-backed storage implementation for CertMagic. It implements the certmagic.Storage and certmagic.Locker interfaces using a pure Go SQLite driver (no CGO required).
Index ¶
- type Option
- type SQLiteStorage
- func (s *SQLiteStorage) Close() error
- func (s *SQLiteStorage) Delete(ctx context.Context, key string) error
- func (s *SQLiteStorage) Exists(ctx context.Context, key string) bool
- func (s *SQLiteStorage) List(ctx context.Context, prefix string, recursive bool) ([]string, error)
- func (s *SQLiteStorage) Load(ctx context.Context, key string) ([]byte, error)
- func (s *SQLiteStorage) Lock(ctx context.Context, name string) error
- func (s *SQLiteStorage) Stat(ctx context.Context, key string) (certmagic.KeyInfo, error)
- func (s *SQLiteStorage) Store(ctx context.Context, key string, value []byte) error
- func (s *SQLiteStorage) Unlock(ctx context.Context, name string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*SQLiteStorage)
Option configures a SQLiteStorage instance.
func WithLockTTL ¶
WithLockTTL sets the duration after which locks expire. Default is 2 minutes.
func WithOwnerID ¶
WithOwnerID sets a custom owner identifier for distributed locking. By default, a random UUID is generated on each instantiation.
Providing a stable ownerID (e.g., hostname, instance ID) allows the application to clean up its own stale locks after a restart, rather than waiting for them to expire.
For single-instance deployments, use a stable ID like hostname. For multi-instance deployments, ensure each instance has a unique ID.
func WithQueryTimeout ¶
WithQueryTimeout sets the timeout for database queries. Default is 3 seconds.
type SQLiteStorage ¶
type SQLiteStorage struct {
// contains filtered or unexported fields
}
SQLiteStorage implements certmagic.Storage and certmagic.Locker using a SQLite database for persistence.
func New ¶
func New(dsn string, opts ...Option) (*SQLiteStorage, error)
New creates a new SQLiteStorage instance. The dsn parameter should be a path to the SQLite database file, or ":memory:" for an in-memory database. The storage will manage the database connection and close it when Close() is called. Recommended PRAGMAs (WAL, synchronous=NORMAL, busy_timeout) are applied automatically.
func NewWithDB ¶
func NewWithDB(db *sql.DB, opts ...Option) (*SQLiteStorage, error)
NewWithDB creates a new SQLiteStorage instance using an existing database connection. This allows sharing a SQLite database with other parts of your application. The caller is responsible for closing the database connection. Schema migrations will be run automatically.
func (*SQLiteStorage) Close ¶
func (s *SQLiteStorage) Close() error
Close closes the database connection if it was opened by New(). If the storage was created with NewWithDB(), this is a no-op.
func (*SQLiteStorage) Delete ¶
func (s *SQLiteStorage) Delete(ctx context.Context, key string) error
Delete removes the key and all keys with the same prefix.
func (*SQLiteStorage) Exists ¶
func (s *SQLiteStorage) Exists(ctx context.Context, key string) bool
Exists returns true if the key exists (either as a file or prefix).
func (*SQLiteStorage) List ¶
List returns all keys with the given prefix. If recursive is false, only direct children are returned. Returns fs.ErrNotExist if no keys match.
func (*SQLiteStorage) Load ¶
Load retrieves the value at the given key. Returns fs.ErrNotExist if the key does not exist.
func (*SQLiteStorage) Lock ¶
func (s *SQLiteStorage) Lock(ctx context.Context, name string) error
Lock acquires a named lock, blocking until the lock is acquired or the context is cancelled.
func (*SQLiteStorage) Stat ¶
Stat returns information about the key. Returns fs.ErrNotExist if the key does not exist.