go-auditGo Audit
Schema

audit_api_logs Table

Schema and examples for the API call log table.

The audit_api_logs table records outbound HTTP requests to third-party services so you can correlate them with the data changes they drove.

Table name is configurable via APIAudit.Table; the default is audit_api_logs.

Schema

ColumnPostgreSQLMySQLSQLiteDescription
idBIGSERIAL PKBIGINT UNSIGNED PKINTEGERAuto-increment primary key
serviceVARCHAR(100)VARCHAR(100)TEXTService name (bca, jne)
endpointVARCHAR(500)VARCHAR(500)TEXTAPI endpoint path
methodVARCHAR(10)VARCHAR(10)TEXTGET, POST, PUT, DELETE
status_codeINTINTINTEGERHTTP status code
request_headersJSONBJSONTEXTRequest headers (redacted)
response_headersJSONBJSONTEXTResponse headers (redacted)
request_bodyJSONBJSONTEXTRequest body (redacted, truncated)
response_bodyJSONBJSONTEXTResponse body (redacted, truncated)
duration_msINTINTINTEGERRequest duration
error_messageTEXTTEXTTEXTError, if failed
user_idVARCHAR(100)VARCHAR(100)TEXTWho triggered the call
metadataJSONBJSONTEXTExtra context
transaction_idVARCHAR(100)VARCHAR(100)TEXTLinks to data changes
created_atTIMESTAMPTZTIMESTAMPDATETIMEWhen the call was made

Indexes

All dialects create these indexes:

idx_<table>_service     (service, created_at)
idx_<table>_status      (status_code)
idx_<table>_user        (user_id)
idx_<table>_created     (created_at)
idx_<table>_transaction (transaction_id)

Go Struct

Go
type AuditAPILog struct {
    ID              uint64          `json:"id"`
    Service         string          `json:"service"`
    Endpoint        string          `json:"endpoint"`
    Method          string          `json:"method"`
    StatusCode      int             `json:"status_code"`
    RequestHeaders  json.RawMessage `json:"request_headers,omitempty"`
    ResponseHeaders json.RawMessage `json:"response_headers,omitempty"`
    RequestBody     json.RawMessage `json:"request_body,omitempty"`
    ResponseBody    json.RawMessage `json:"response_body,omitempty"`
    DurationMs      int             `json:"duration_ms"`
    ErrorMessage    string          `json:"error_message,omitempty"`
    UserID          string          `json:"user_id,omitempty"`
    Metadata        json.RawMessage `json:"metadata,omitempty"`
    TransactionID   string          `json:"transaction_id,omitempty"`
    CreatedAt       time.Time       `json:"created_at"`
}
Go snippet

RequestHeaders, ResponseHeaders, RequestBody, ResponseBody, and Metadata are json.RawMessage — decode them into whatever shape your caller expects.

Upgrading from v1.0.x

response_headers was added in v1.1.0. AutoMigrate uses CREATE TABLE IF NOT EXISTS, so existing deployments must add the column manually before upgrading:

SQL
-- PostgreSQL
ALTER TABLE audit_api_logs ADD COLUMN response_headers JSONB;

-- MySQL
ALTER TABLE audit_api_logs ADD COLUMN response_headers JSON;

-- SQLite
ALTER TABLE audit_api_logs ADD COLUMN response_headers TEXT;
SQL snippet

Fresh installs running v1.1.0+ get the column automatically.

Example Records

Payment API call

JSON
{
  "service": "bca",
  "endpoint": "/v1/transfer",
  "method": "POST",
  "status_code": 200,
  "request_headers": {
    "Authorization": "***REDACTED***",
    "Content-Type": "application/json"
  },
  "request_body": { "amount": 100000, "account": "1234567890" },
  "response_body": { "reference": "BCA-TRX-42", "status": "success" },
  "duration_ms": 842,
  "user_id": "admin-1",
  "transaction_id": "20260413T090000-a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6",
  "created_at": "2026-04-13T09:00:00Z"
}
JSON snippet

Truncated response

JSON
{
  "service": "jne",
  "endpoint": "/v2/tracking",
  "method": "GET",
  "status_code": 200,
  "response_body": {
    "_truncated": true,
    "original_size": 128512,
    "preview": "{\"status\":\"in_transit\",\"history\":["
  },
  "duration_ms": 230,
  "transaction_id": "20260413T090000-a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6",
  "created_at": "2026-04-13T09:00:01Z"
}
JSON snippet

On this page