memory

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package memory is graudit's test/dev-only backend. It stores entries in a single mutex-protected slice — the mutex is both the storage guard and the chain's serialization point — and does not coordinate state across processes or replicas. Never use this backend for anything you need to keep; use graudit/postgres or graudit/mongo for durable storage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMemoryAuditLog

func NewMemoryAuditLog(opts ...Option) (graudit.AuditLog, error)

NewMemoryAuditLog constructs a ready-to-use in-memory AuditLog. Construction never fails — the error return exists only to match the signature every other backend's constructor uses.

Parameters:

  • opts: ...Option — WithLogger and/or WithEventBus; both optional

Returns:

  • graudit.AuditLog: ready to use immediately
  • error: always nil

Types

type AuditLog

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

AuditLog is an in-memory implementation of graudit.AuditLog. It has zero external dependencies and does not coordinate state across processes or replicas — running it behind multiple instances of an application means each instance has its own independent, diverging chain, which is expected, not a bug. Use graudit/postgres or graudit/mongo for state that must be shared and durable.

func (*AuditLog) Close

func (a *AuditLog) Close() error

Close implements graudit.AuditLog.Close; idempotent via sync.Once.

func (*AuditLog) Query

func (a *AuditLog) Query(ctx context.Context, filter graudit.QueryFilter) ([]graudit.AuditEvent, error)

Query implements graudit.AuditLog.Query; see the interface's doc comment for the full contract. This is a linear scan over the in-memory slice — acceptable specifically because this is the test/dev-only backend, never the production one.

func (*AuditLog) Record

func (a *AuditLog) Record(ctx context.Context, event graudit.AuditEvent) (graudit.EntryID, error)

Record implements graudit.AuditLog.Record; see the interface's doc comment for the full contract. Locking here doubles as the chain's single-writer serialization point — the mutex is held across the entire read-tail/compute-hash/append sequence.

func (*AuditLog) RecordChange

func (a *AuditLog) RecordChange(ctx context.Context, actorID, entityType, entityID string, before, after any) (graudit.EntryID, error)

RecordChange implements graudit.AuditLog.RecordChange; see the interface's doc comment for the full contract.

func (*AuditLog) Verify

func (a *AuditLog) Verify(ctx context.Context, from, to graudit.EntryID) (bool, graudit.VerifyResult, error)

Verify implements graudit.AuditLog.Verify; see the interface's doc comment for the full contract and verifyChain's doc comment for the two-check design.

type Option

type Option func(*AuditLog)

Option configures an AuditLog constructed by NewMemoryAuditLog.

func WithEventBus

func WithEventBus(bus grevents.Bus) Option

WithEventBus installs an optional grevents.Bus. When set, every successful Record publishes a graudit.TopicAuditRecorded event. A nil/ unconfigured bus (the default) means Record simply doesn't publish — not an error.

func WithLogger

func WithLogger(l graudit.Logger) Option

WithLogger installs an optional graudit.Logger for diagnostic messages (grevents publish failures). Logging is always opt-in.

Jump to

Keyboard shortcuts

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