audit

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package audit 提供写操作审计原语:审计记录与业务写在同一事务内落库, 事务回滚则审计一并消失——审计反映的是"已发生的事实"。

PSP 约定:资金相关的每次状态变更(记账、退款、改配置)都应留一条审计。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MigrationSQL

func MigrationSQL(schema string) string

MigrationSQL 返回审计表 DDL(幂等),域 repo 把它并入自己的基础迁移。

func MigrationSQLBare

func MigrationSQLBare() string

MigrationSQLBare 返回无 schema 前缀的审计表 DDL,供分区域域 (appkit new domain -partitioned)的迁移使用:目标 schema 由 pgmigrate 在应用时经 SET LOCAL search_path 落位。两版的列定义必须保持一致。

Types

type Entry

type Entry struct {
	Actor    string // 操作者(用户 ID、服务名、"system")
	Action   string // 动作(如 "entry.post"、"refund.approve")
	Entity   string // 实体类型(如 "ledger_entry")
	EntityID string
	Before   any
	After    any
	Meta     any
}

Entry 是一条审计记录。Before/After/Meta 会被 JSON 序列化(可为 nil)。

type Recorder

type Recorder struct {
	// contains filtered or unexported fields
}

Recorder 绑定 pool 与 schema,在 wiring 期构造后注入业务层 (业务层按"接口放消费方"依赖单方法接口,不 import 本包)。

func NewRecorder

func NewRecorder(pool *pgxpool.Pool, schema string) *Recorder

func (*Recorder) Record

func (r *Recorder) Record(ctx context.Context, e Entry) error

Record 在当前事务内写入一条审计。必须在事务内调用——审计脱离业务事务 就失去了"与事实同生共死"的意义。

Jump to

Keyboard shortcuts

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