Documentation
¶
Index ¶
- func AuditCreate(a AuditAdapter, entity interface{}, entityName, entityId string)
- func AuditDelete(a AuditAdapter, entity interface{}, entityName, entityId string)
- func AuditPatch(a AuditAdapter, entity interface{}, entityName, entityId string, ...)
- func GroupStructToMap(entity interface{}, tagName string) map[string]interface{}
- func GroupStructToMapUpdated(entity interface{}, tagName string, fields map[string]interface{}) map[string]AuditUpdate
- func KeysToString(keys ...interface{}) string
- type Audit
- type AuditAdapter
- type AuditColumns
- type AuditFile
- type AuditSQL
- type AuditUpdate
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 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 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 ¶
type AuditUpdate ¶
type AuditUpdate struct {
From interface{} `json:"from"`
To interface{} `json:"to"`
}
Click to show internal directories.
Click to hide internal directories.