audit

package
v1.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

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

func Record(ctx context.Context, q db.Querier, e Event) error

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

func RecordOrWarn(ctx context.Context, q db.Querier, e Event)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL