
audit
Package audit provides request ID propagation and structured audit logging for security-relevant operations.
Index
- func Log(ctx context.Context, event string, attrs …slog.Attr)
- func NewID() string
- func RequestID(ctx context.Context) string
- func SetOnEvent(fn func(event string))
- func WithRequestID(ctx context.Context, id string) context.Context
func Log
Log emits a structured audit log entry at Info level. Automatically includes the request ID from context. If OnEvent is set, it is called with the event name for metrics integration.
func NewID
NewID generates a hex-encoded 16-byte random ID suitable for request correlation. crypto/rand.Read always returns len(b) and nil error on all supported platforms (see Go docs), so no error handling is needed.
func RequestID
RequestID extracts the request ID from the context. Returns empty string if no request ID is set.
func SetOnEvent
SetOnEvent registers a callback invoked for each audit event. Pass nil to clear a previously registered callback.
func WithRequestID
WithRequestID stores a request ID in the context.
Generated by gomarkdoc