API Reference
Public methods on the Auditor type. All methods accept a context.Context and return errors using fmt.Errorf wrapping for cause inspection.
Query audit logs by entity, action, or date range. Supports cursor-based pagination and returns entries ordered by occurredAt descending.
ctxcontext.ContextRequest-scoped context, propagated to the underlying SQL driver.optsQueryOptionsFilter, ordering, and pagination knobs. See QueryOptions.([]Entry, error)entries, err := auditor.Query(ctx, audit.QueryOptions{
Entity: "users",
Action: "update",
Limit: 50,
})
Log third-party API calls with automatic header and body redaction. Headers like Authorization and Cookie are masked, and JSON paths can be configured for body redaction.
ctxcontext.ContextRequest context. Cancellation aborts the write.callAPICallOutbound HTTP call snapshot — endpoint, status, latency, headers, body.errorerr := auditor.API().Record(ctx, audit.APICall{
Endpoint: "https://api.stripe.com/v1/charges",
Method: "POST",
Status: 200,
Latency: 180 * time.Millisecond,
})
Retrieve entity state at a specific point in time by replaying audit log entries up to the cutoff. Read-only — does not modify any data.
ctxcontext.ContextCancelable context for the read.entityIDstringStable identifier of the entity to reconstruct.asOftime.TimeCutoff timestamp; UTC recommended.(Snapshot, error)snap, err := auditor.Snapshot(ctx, "user-42", cutoff)
if err != nil { return err }
// snap.State is the projected entity at `cutoff`.
Revert an entity to its state at a previous timestamp. The restore itself is recorded as a new audit entry, preserving the full chain of changes.
ctxcontext.ContextCancelable context for the write transaction.entityIDstringIdentifier of the entity to roll back.asOftime.TimeTarget timestamp to restore to.errorif err := auditor.Restore(ctx, "user-42", t); err != nil {
log.Fatal(err)
}
Permanently delete audit log entries older than the cutoff. Returns the number of rows deleted. Use with caution — purged data cannot be recovered.
ctxcontext.ContextCancelable context. Cancellation rolls back uncommitted batches.beforetime.TimeAll entries strictly older than this timestamp are removed.(int64, error)n, err := auditor.Purge(ctx, time.Now().AddDate(-1, 0, 0))
// n is the number of rows removed.