go-auditGo Audit

Go Audit

Automatic audit trail and API call logging for Go applications.

Go Audit provides automatic audit trail and API call logging for Go applications. Register a plugin with your ORM, and every create, update, and delete is captured — who changed what, when, and from what value to what value.

The core package has zero network dependencies and relies only on the Go standard library. ORM integrations ship as separate sub-packages so you only import what you use.

Key Features

  • ORM Auto-Hooks — GORM, Bun, Ent (zero manual code)
  • Auto Diff — on updates, only changed fields are stored
  • API Call Logging — track third-party HTTP calls with redaction
  • Multi-Database — PostgreSQL, MySQL, SQLite
  • Transaction Correlation — link data changes + API calls by ID
  • Query Builder — typed filters for entity, user, action, range
  • Snapshot & Restore — reconstruct entity state at any point in time
  • RetentionPurge rows older than a cutoff

Quick Navigation

Built for AI-assisted development

Go Audit ships with a Claude Skill so Claude Code can integrate the library into a Go project from a cold prompt, and a read-only MCP server so you can query audit history conversationally during incidents:

"Show me every change to order #42 in the last 24 hours."

See AI Integration → Overview.

Install

go get github.com/gopackx/go-audit

Minimal Example

Go
import (
    "context"
    "database/sql"

    "github.com/gopackx/go-audit"
    auditgorm "github.com/gopackx/go-audit/adapters/gorm"
    "gorm.io/driver/postgres"
    "gorm.io/gorm"
)

gormDB, _ := gorm.Open(postgres.Open(dsn), &gorm.Config{})
sqlDB, _ := gormDB.DB()

auditor, err := audit.New(sqlDB, audit.Config{
    Dialect: audit.PostgreSQL,
    UserFunc: func(ctx context.Context) (string, string) {
        return "user-123", "user"
    },
    DataAudit: audit.DataAuditConfig{Enabled: true},
})
if err != nil {
    panic(err)
}

_ = gormDB.Use(auditgorm.Plugin(auditor))
_ = auditor.AutoMigrate(context.Background())
Go snippet

That's it. Every create, update, and delete through GORM is now tracked in the audit_logs table automatically.

On this page