audit

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MIT Imports: 6 Imported by: 0

README

audit — audit-trail event capture

import "github.com/downsized-devs/sdk-go/audit"

Stability: Stable — see STABILITY.md

Captures domain events with the request/user context already on context.Context. Persistent log stream separate from operational logger lines.

Features

  • Capture / Record for fire-and-forget event capture
  • Auto-attaches requestId, userId from appcontext and auth info from auth
  • Single Interface for easy mocking

Installation

go get github.com/downsized-devs/sdk-go/audit

Quick Start

a := audit.Init(audit.Config{})
a.Capture(ctx, audit.Collection{
    Resource: "user",
    Action:   "update",
    Before:   oldUser,
    After:    newUser,
})

API Reference

Symbol Signature
Init func Init(cfg Config) Interface
Interface.Capture (ctx, Collection)
Interface.Record (ctx, Collection)
Collection Resource/action/before/after payload (see audit/entity.go).

Error Handling

Capture/Record do not return errors — failures are logged but never block business logic.

Dependencies

Testing

go test ./audit/...

Contributing

See CONTRIBUTING.md.

  • logger — operational logs vs durable audit events.
  • appcontext — provides request/user metadata.
  • auth — provides current-user info.

Documentation

Overview

Package audit emits structured audit records (HTTP captures and domain-level Record events) as zerolog log lines, enriched from the surrounding appcontext and the resolved user identity.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collection

type Collection struct {
	EventName        string
	EventDescription string
	RequestBody      any
	InsertParam      any
	SelectParam      any
	UpdateParam      any
	Error            error
}

type Interface

type Interface interface {
	Capture(ctx context.Context)
	Record(ctx context.Context, log Collection)
}

func Init

func Init(auth auth.Interface) Interface

Jump to

Keyboard shortcuts

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