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 ¶
- func NewMemoryAuditLog(opts ...Option) (graudit.AuditLog, error)
- type AuditLog
- func (a *AuditLog) Close() error
- func (a *AuditLog) Query(ctx context.Context, filter graudit.QueryFilter) ([]graudit.AuditEvent, error)
- func (a *AuditLog) Record(ctx context.Context, event graudit.AuditEvent) (graudit.EntryID, error)
- func (a *AuditLog) RecordChange(ctx context.Context, actorID, entityType, entityID string, before, after any) (graudit.EntryID, error)
- func (a *AuditLog) Verify(ctx context.Context, from, to graudit.EntryID) (bool, graudit.VerifyResult, error)
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewMemoryAuditLog ¶
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) 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 ¶
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.
type Option ¶
type Option func(*AuditLog)
Option configures an AuditLog constructed by NewMemoryAuditLog.
func WithEventBus ¶
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 ¶
WithLogger installs an optional graudit.Logger for diagnostic messages (grevents publish failures). Logging is always opt-in.