Documentation
¶
Overview ¶
Package main demonstrates the command Audit Logging middleware.
This example shows:
- Wiring AuditMiddleware into a CommandBus (with RecoveryMiddleware nested inside, so even a panicking handler is recorded as a failed audit entry)
- Auditing successful AND failing commands
- Skipping selected command types from the audit trail
- Identifying the actor via WithActor on the context
- Querying the audit trail with AuditQuery
It uses the in-memory audit store, so it runs with NO database:
go run ./examples/audit
For production, swap the in-memory store for the PostgreSQL store. The audit table is created by store.Initialize (it is NOT part of the adapter's migrations):
db, _ := sql.Open("postgres", connStr) // import _ "github.com/lib/pq"
auditStore := postgres.NewAuditStore(db,
postgres.WithAuditSchema("public"),
postgres.WithAuditTable("mink_audit"),
)
_ = auditStore.Initialize(ctx)
// then: mink.AuditMiddleware(mink.DefaultAuditConfig(auditStore))
Click to show internal directories.
Click to hide internal directories.