audit

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package audit writes the audit log (audit_logs): who did what to what, from where.

A change and its record belong in one transaction: a record written afterwards is lost when its write fails, and one written before records changes that then roll back. Services that make administrative changes therefore take an *Entry and write it inside their transaction (nil: nothing to record, e.g. a user's own change).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Write

func Write(ctx context.Context, c *ent.Client, e *Entry) error

Write records e through c, normally the transaction of the change. A nil e writes nothing.

Types

type Entry

type Entry struct {
	Actor      *int64 // the user acting; nil for the system or the admin token
	Action     string // e.g. "admin.player_updated"
	TargetType string
	TargetID   string
	IP         string
	Meta       map[string]any
}

Entry is one audit record.

func (*Entry) Target

func (e *Entry) Target(typ, id string) *Entry

Target returns a copy of e naming the target (e may be nil: then nil), for a service that learns the target's id inside the transaction (a new row).

func (*Entry) With

func (e *Entry) With(key string, value any) *Entry

With returns a copy of e with key set in Meta (e may be nil: then nil).

Jump to

Keyboard shortcuts

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