audit

package
v0.1.19 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SoftDelete

func SoftDelete(ctx context.Context, auditable *Auditable)

SoftDelete Marks `auditable` as deleted. It also increases the version, updates last update fields, both time and by.

This routine takes `ctx` argument to retrieve the identity.Principal instance performing the operation. If no principal is found, an `unknown` value will be placed instead.

func Touch

func Touch(ctx context.Context, auditable *Auditable)

Touch increases the version, updates last update fields, both time and by.

This routine takes `ctx` argument to retrieve the identity.Principal instance performing the operation. If no principal is found, an `unknown` value will be placed instead.

Types

type Auditable

type Auditable struct {
	CreateTime     time.Time
	CreateBy       string
	LastUpdateTime time.Time
	LastUpdateBy   string
	Version        int64
	IsDeleted      bool
	// contains filtered or unexported fields
}

Auditable is a structure provisioning metadata for persistence operations.

Embed this structure into your entities/aggregates to enhance and control write operations. Call New routine to create an instance with default values.

Implements persistence.Storable interface.

func New

func New(ctx context.Context, opts ...AuditableOption) Auditable

New allocates a new Auditable instance using default values.

This routine takes `ctx` argument to retrieve the identity.Principal. If no principal is found, an `unknown` value will be placed instead. The principal is used to set the `CreateBy` and `LastUpdateBy` fields.

Use AuditableOption routines to customize how the instance is created.

func (Auditable) IsNew

func (a Auditable) IsNew() bool

IsNew checks if the type was just created.

type AuditableOption

type AuditableOption func(auditable *Auditable)

AuditableOption routine used to set non-required options to Auditable-related routines.

func WithCreateTime

func WithCreateTime(t time.Time) AuditableOption

WithCreateTime sets the creation time for Auditable.

func WithLocation

func WithLocation(loc *time.Location) AuditableOption

WithLocation sets the location for Auditable default timestamps.

This value will be ignored if any of the `createTime` or `updateTime` options are set.

func WithUpdateTime

func WithUpdateTime(t time.Time) AuditableOption

WithUpdateTime sets the last update time for Auditable.

func WithVersion

func WithVersion(version int64) AuditableOption

WithVersion sets the initial version for Auditable.

Jump to

Keyboard shortcuts

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