audit

package
v0.0.0-...-6d6c219 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuditCreate

func AuditCreate(a AuditAdapter, entity interface{}, entityName, entityId string)

func AuditDelete

func AuditDelete(a AuditAdapter, entity interface{}, entityName, entityId string)

func AuditPatch

func AuditPatch(a AuditAdapter, entity interface{}, entityName, entityId string, existingValues map[string]interface{})

func GroupStructToMap

func GroupStructToMap(entity interface{}, tagName string) map[string]interface{}

func GroupStructToMapUpdated

func GroupStructToMapUpdated(entity interface{}, tagName string, fields map[string]interface{}) map[string]AuditUpdate

func KeysToString

func KeysToString(keys ...interface{}) string

Types

type Audit

type Audit struct {
	CreatedAt time.Time              `json:"created_at"`
	Created   map[string]interface{} `json:"created,omitempty"`
	Updated   map[string]AuditUpdate `json:"updated,omitempty"`
	Delete    map[string]interface{} `json:"delete,omitempty"`
	UserID    int                    `json:"user_id,omitempty"`
	UserUID   string                 `json:"user_uid,omitempty"`
	Entity    string                 `json:"entity,omitempty"`
	EntityID  string                 `json:"entity_id,omitempty"`
}

type AuditAdapter

type AuditAdapter interface {
	WriteAudit(Audit)
}

func AuditInit

func AuditInit() AuditAdapter
if you are using this, you will need to create a table

CREATE TABLE IF NOT EXISTS audit (

id INT AUTO_INCREMENT, -- or SERIAL
user_id int null,
user_uid varchar(50) null,
entity VARCHAR(50) NOT NULL,
entity_id VARCHAR(50) NOT NULL,
changed JSON NOT NULL, -- may not work with sqlite
created_at DATETIME NOT NULL, -- or TIMESTAMP
PRIMARY KEY(id)

);

type AuditColumns

type AuditColumns struct {
	Created map[string]interface{} `json:"created,omitempty"`
	Updated map[string]AuditUpdate `json:"updated,omitempty"`
	Delete  map[string]interface{} `json:"delete,omitempty"`
}

type AuditFile

type AuditFile struct {
	FilePath string
}

func (AuditFile) WriteAudit

func (h AuditFile) WriteAudit(audit Audit)

type AuditSQL

type AuditSQL struct {
	DB        *sqlx.DB
	CreatedAt time.Time       `db:"created_at"`
	Entity    string          `db:"entity"`
	EntityID  string          `db:"entity_id"`
	Changed   json.RawMessage `db:"changed"`
	UserID    int             `db:"user_id"`
	UserUID   string          `db:"user_uid"`
}

func (AuditSQL) WriteAudit

func (h AuditSQL) WriteAudit(audit Audit)

type AuditUpdate

type AuditUpdate struct {
	From interface{} `json:"from"`
	To   interface{} `json:"to"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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