pgxmagic is a pgx-driven implementation of certmagic.Storage designed to fit in to an existing golang+pgx codebase.
- Uses an existing pgxpool: No need to maintain a separate database connection just for CertMagic
- Session-level advisory locks: Uses
pg_try_advisory_lockto handle distributed locking - Migrations are optional: Convenience method to do this for you, but only if you want.
- Focus on correctness: Complete implementation of
certmagic.Storagewith a full test suite. - Optional encryption: An
EncryptedStorageadapter exists to allow for encryption of values.
Optionally, add the following as a database migration.
If you'd prefer not to, you can call storage.Migrate() to do this idempotently instead.
CREATE TABLE IF NOT EXISTS certmagic_data (
key TEXT PRIMARY KEY,
value bytea,
modified timestamptz DEFAULT NOW()
);
Certificates are stored in the clear in the database
storage := pgxmagic.NewStorage(pool)
err := storage.Migrate(context.Background()) // Optional, or manually create table.Certificates are stored encrypted in the database -- in this case, encrypted with AES-256.
storage := pgxmagic.NewEncryptedStorage(
pool,
pgxmagic.NewAES256Encrypter("correct horse battery staple"),
)- No Caddy plugin: This was built to slot into an existing go codebase that's using CertMagic directly. A plugin could easily be created if needed though.