Documentation
¶
Overview ¶
Package audit implements async event dispatching for security-relevant operations.
Components ¶
- Sink — interface for event consumers (channel, JSON writer, no-op).
- Dispatcher — buffered async relay with drop-if-full / block-if-full semantics.
- Event — structured audit record with timestamp, type, user, tenant, IP, metadata.
Architecture boundaries ¶
This package owns event buffering and sink delivery. It does NOT decide which events to emit — that responsibility belongs to the Engine and flow functions.
What this package must NOT do ¶
- Filter or suppress events based on business logic.
- Import goAuth or any sibling internal package.
- Perform network I/O beyond what a caller-supplied Sink does.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChannelSink ¶
type ChannelSink struct {
// contains filtered or unexported fields
}
ChannelSink writes audit events into a buffered channel.
func NewChannelSink ¶
func NewChannelSink(buffer int) *ChannelSink
func (*ChannelSink) Events ¶
func (s *ChannelSink) Events() <-chan Event
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher asynchronously forwards audit events to a sink.
func NewDispatcher ¶
func NewDispatcher(cfg Config, sink Sink) *Dispatcher
func (*Dispatcher) Close ¶
func (d *Dispatcher) Close()
func (*Dispatcher) Dropped ¶
func (d *Dispatcher) Dropped() uint64
func (*Dispatcher) SinkErrors ¶ added in v0.2.0
func (d *Dispatcher) SinkErrors() uint64
SinkErrors returns the number of sink-level write errors reported by the configured sink. Sinks that do not expose error counts return 0.
type Event ¶
type Event struct {
Timestamp time.Time `json:"timestamp"`
EventType string `json:"event_type"`
UserID string `json:"user_id,omitempty"`
TenantID string `json:"tenant_id,omitempty"`
SessionID string `json:"session_id,omitempty"`
IP string `json:"ip,omitempty"`
Success bool `json:"success"`
Error string `json:"error,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
}
Event is the canonical audit event model used by internal dispatching and root APIs.
type JSONWriterSink ¶
type JSONWriterSink struct {
// contains filtered or unexported fields
}
JSONWriterSink writes one JSON object per line.
func NewJSONWriterSink ¶
func NewJSONWriterSink(w io.Writer) *JSONWriterSink
func (*JSONWriterSink) ErrorCount ¶ added in v0.2.0
func (s *JSONWriterSink) ErrorCount() uint64
ErrorCount returns the number of JSON encoding or write failures observed by this sink.
type SlogSink ¶ added in v0.2.0
type SlogSink struct {
// contains filtered or unexported fields
}
SlogSink writes audit events through a slog.Logger for easy integration with structured log backends.
func NewSlogSink ¶ added in v0.2.0
NewSlogSink creates a SlogSink that writes audit events at info level.