audit

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuditLog

type AuditLog struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	UserID    uint      `gorm:"index;not null;default:0" json:"user_id"`
	Action    string    `gorm:"size:50;not null;index" json:"action"`
	ModelType string    `gorm:"size:100;not null;index" json:"model_type"`
	ModelID   uint      `gorm:"not null;index" json:"model_id"`
	OldValues string    `gorm:"type:text" json:"old_values,omitempty"`
	NewValues string    `gorm:"type:text" json:"new_values,omitempty"`
	Metadata  string    `gorm:"type:text" json:"metadata,omitempty"`
	CreatedAt time.Time `json:"created_at"`
}

AuditLog records a single auditable action on a model.

type Entry

type Entry struct {
	UserID    uint
	Action    string
	ModelType string
	ModelID   uint
	OldValues map[string]interface{}
	NewValues map[string]interface{}
	Metadata  map[string]interface{}
}

Entry holds the data for a single audit log record.

type Logger

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

Logger writes audit log entries to the database.

func NewLogger

func NewLogger(db *gorm.DB) *Logger

NewLogger creates a new audit Logger backed by the given database connection.

func (*Logger) Find

func (l *Logger) Find(query string, args ...interface{}) ([]AuditLog, error)

Find returns audit log entries matching the given conditions, ordered newest first. Conditions use GORM Where syntax: Find("user_id = ?", 42).

func (*Logger) ForModel

func (l *Logger) ForModel(modelType string, modelID uint) ([]AuditLog, error)

ForModel returns all audit log entries for a specific model type and ID.

func (*Logger) Log

func (l *Logger) Log(e Entry) error

Log persists an audit entry to the database.

Jump to

Keyboard shortcuts

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