auditrest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package auditrest is the REST integration for auditlog: a read-side handler group (history / diff / changes) mountable on any skit router in one call. See handlers.go.

Recording is intentionally not done here — audit at the domain layer via the auditbus eventbus adapter or a direct auditlog.Core.Create, which covers every transport (HTTP, gRPC, workers, consumers) uniformly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppAuditLog

type AppAuditLog struct {
	ID        int             `json:"id"`
	Version   int             `json:"version"`
	ModelType string          `json:"model_type"`
	ModelID   string          `json:"model_id"`
	Method    string          `json:"method"`
	Path      string          `json:"path"`
	Payload   json.RawMessage `json:"payload"`
	CreatedAt time.Time       `json:"created_at"`
	CreatedBy string          `json:"created_by"`
}

AppAuditLog is the REST representation of a single audit log version.

type AppDiff

type AppDiff struct {
	ModelType string `json:"model_type"`
	ModelID   string `json:"model_id"`
	Diff      string `json:"diff"`
}

AppDiff is the textual diff between two versions of a model.

type AppField

type AppField struct {
	Key      string `json:"key"`
	OldValue any    `json:"old_value"`
	NewValue any    `json:"new_value"`
}

AppField is a single changed attribute between two versions.

type AppRecord

type AppRecord struct {
	Version       int        `json:"version"`
	ModelType     string     `json:"model_type"`
	ModelID       string     `json:"model_id"`
	Method        string     `json:"method"`
	Path          string     `json:"path"`
	UpdatedBy     *string    `json:"updated_by,omitempty"`
	UpdatedAt     *time.Time `json:"updated_at,omitempty"`
	ChangedFields []AppField `json:"changed_fields"`
}

AppRecord is one version with the fields that changed since the previous one.

type Handlers

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

Handlers is the read-side REST API for the audit log: history, diff between two versions, and changed-fields across all versions. Mount it on any skit router in one call with Routes; pair it with Middleware for the write side.

func NewHandlers

func NewHandlers(core *auditlog.Core) *Handlers

NewHandlers builds the audit-log query handlers over core.

func (*Handlers) Routes

func (h *Handlers) Routes(handle rest.Handle, mw ...rest.MidFunc)

Routes registers the audit-log read endpoints through the handle seam, so the audit API does not depend on the router type. Pass authorization middleware (e.g. admin-only) in mw to protect every endpoint:

auditrest.NewHandlers(auditCore).Routes(r.HandleApp, adminOnly)

Jump to

Keyboard shortcuts

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