Features
Custom Table Names
Rename audit tables to match your project's naming conventions.
The default tables are audit_logs (data changes) and audit_api_logs
(API calls). You can override either independently.
Configuration
auditor, _ := audit.New(sqlDB, audit.Config{
Dialect: audit.PostgreSQL,
DataAudit: audit.DataAuditConfig{
Enabled: true,
Table: "app_audit_events",
},
APIAudit: audit.APIAuditConfig{
Enabled: true,
Table: "app_outbound_calls",
},
})AutoMigrate(ctx) creates the tables under your chosen names, and
all queries (Query, API().Query, QueryByTransaction, Purge)
automatically use the configured names.
Validation
Table names are validated against ^[A-Za-z_][A-Za-z0-9_]{0,62}$ —
standard SQL identifier rules. audit.New returns an error if either
table name is invalid:
_, err := audit.New(sqlDB, audit.Config{
DataAudit: audit.DataAuditConfig{Table: "bad table name"},
})
// err != nil — spaces are not allowedUse Cases
- Multi-tenant schemas. Prefix tables with a tenant identifier:
tenant42_audit_logs. - Naming conventions. Match an existing project style (singular vs plural, snake_case vs PascalCase).
- Parallel installs. Run two
Auditorinstances side-by-side with different tables for different subsystems (e.g. one per bounded context).
Migrating Existing Tables
Go Audit does not rename tables automatically. If you change
DataAudit.Table after records exist:
- Create the new table via
auditor.AutoMigrate(ctx). - Copy rows from the old table (
INSERT INTO new SELECT ... FROM old). - Update reads and drop the old table once you're confident.