go-auditGo Audit
Features

Multi-Database Support

First-class PostgreSQL, MySQL, and SQLite with dialect-aware storage.

Go Audit ships with three dialect implementations. Each generates schema DDL, places parameter placeholders, and chooses a JSON storage strategy appropriate for its database.

PostgreSQL

  • JSONB for old_values, new_values, request_headers, request_body, response_body, metadata
  • GIN indexes on old_values and new_values for JSON key lookups
  • TIMESTAMPTZ with DEFAULT NOW() for created_at
  • BIGSERIAL primary key
  • Parameter placeholders: $1, $2, …

MySQL

  • JSON type for JSON columns
  • B-tree indexes declared inline in CREATE TABLE
  • TIMESTAMP with DEFAULT CURRENT_TIMESTAMP for created_at
  • BIGINT UNSIGNED AUTO_INCREMENT primary key
  • Table engine: InnoDB, charset utf8mb4
  • Parameter placeholders: ?

SQLite

  • TEXT for JSON (stored as JSON-encoded strings)
  • B-tree indexes
  • DATETIME with DEFAULT (datetime('now')) for created_at
  • INTEGER PRIMARY KEY AUTOINCREMENT
  • Parameter placeholders: ?

Great for local development, embedded deployments, and tests.

Setting the Dialect

The dialect is explicit — there is no auto-detection based on the driver. Pass the constant directly in Config:

audit.New(sqlDB, audit.Config{
    Dialect: audit.PostgreSQL, // or audit.MySQL / audit.SQLite
    // ...
})

Valid values:

audit.PostgreSQL
audit.MySQL
audit.SQLite

Custom Dialects

You can register a custom dialect to support Aurora, AlloyDB, ClickHouse, or any other database. See the Dialect reference for the interface and registration call.

Record Shape

The stored record shape is identical across dialects — same columns, same JSON structure, same index intent. You can migrate an audit database from SQLite to PostgreSQL by copying rows and re-parsing the JSON text into JSONB.

On this page