Documentation
¶
Overview ¶
Package audit provides structured, durable audit event recording. Every call emits a matching slog INFO line (the primary durable record) and also writes to the audit_log Postgres table (for querying and retention).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Record ¶
Record writes one audit event to the DB via q and emits a matching slog INFO line. q may be tx-wrapped (via q.WithTx(tx)) for atomicity with surrounding DB writes.
The slog line is always emitted, even when the DB write fails. DB errors are returned but not fatal — the slog line is the authoritative audit record.
func RecordOrWarn ¶
RecordOrWarn records an audit event and logs a warning on DB write failure. Use this in handlers where audit persistence failures should not fail the user-facing operation, while still keeping observability of dropped records.
Types ¶
type Event ¶
type Event struct {
Event string
Attrs map[string]any // serialized to JSONB in the DB; nil is fine
}
Event carries the event name and optional extra attributes. Context fields (user_id, source_ip, user_agent, request_id, trace_id) are extracted from ctx automatically by Record — callers need not set them.