audit

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package audit provides a PostMutationHook that logs all mutations to an audit trail (Chronicle). Every INSERT, UPDATE, DELETE is recorded with the table, operation, timestamp, and optionally the changed data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuditEntry

type AuditEntry struct {
	Timestamp time.Time `json:"timestamp"`
	Table     string    `json:"table"`
	Operation string    `json:"operation"`
	Query     string    `json:"query,omitempty"`
	TenantID  string    `json:"tenant_id,omitempty"`
	Data      any       `json:"data,omitempty"`
}

AuditEntry represents a single audit log entry.

type Hook

type Hook struct {
	// contains filtered or unexported fields
}

Hook is a PostMutationHook that records all mutations.

func NewHook

func NewHook(w Writer) *Hook

NewHook creates a new audit hook with the given writer.

func NewLogHook

func NewLogHook(logger log.Logger) *Hook

NewLogHook creates an audit hook that logs to a structured logger.

func (*Hook) AfterMutation

func (h *Hook) AfterMutation(ctx context.Context, qc *hook.QueryContext, data, _ any) error

AfterMutation records the mutation in the audit trail.

type LogWriter

type LogWriter struct {
	Logger log.Logger
}

LogWriter writes audit entries to a structured logger.

func (*LogWriter) WriteEntry

func (w *LogWriter) WriteEntry(_ context.Context, entry *AuditEntry) error

WriteEntry logs the audit entry.

type Writer

type Writer interface {
	WriteEntry(ctx context.Context, entry *AuditEntry) error
}

Writer is the interface for persisting audit entries. Implementations could write to a database, file, message queue, etc.

Jump to

Keyboard shortcuts

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