Introduces code.nochebuena.dev/einherjar/contracts — the zero-dependency foundation of the Einherjar framework. Defines the interfaces and minimal types consumed by every starter. Zero external dependencies. Zero Einherjar dependencies. Nothing is above it in the dependency graph. lifecycle: - Component — OnInit, OnStart, OnStop three-phase lifecycle hooks observability: - Level (LevelCritical=0, LevelDegraded); zero value is the safe default - Checkable — HealthCheck, Name, Priority - Identifiable — ModulePath, ModuleVersion; implemented by all starters to surface module identity and version in the startup banner logging: - Logger — Debug, Info, Warn, Error, With, WithContext errs: - CodedError — ErrorCode() string; satisfied by core/xerrors.Err - ContextualError — ErrorContext() map[string]any; satisfied by core/xerrors.Err security: - Identity value type — UID, TenantID, DisplayName, Email; NewIdentity, WithTenant - Permission (int64), MaxPermission=62, PermissionMask — Has, Grant - PermissionProvider — ResolveMask(ctx, uid, resource) (PermissionMask, error) - SecurityBag value type — immutable request-scoped security context; carries Identity and arbitrary typed attributes (hardware IDs, grant codes, etc.); With copies the attribute map on every call to preserve receiver-invariant behaviour - NewSecurityBag, Identity, WithIdentity, Get, With - SetBagInContext / BagFromContext — full bag context storage - SetInContext / FromContext — backed by SecurityBag; all four cross-function combinations (SetInContext+BagFromContext, SetBagInContext+FromContext) are valid One file per type; CT-6 enforced by compliance test AST walk.
27 lines
1.1 KiB
Go
27 lines
1.1 KiB
Go
package logging
|
|
|
|
import "context"
|
|
|
|
// Logger is the interface for structured, leveled logging.
|
|
// All Einherjar starters accept Logger at their constructors and pass it
|
|
// to sub-components — never the concrete implementation.
|
|
// Implementations must be safe for concurrent use.
|
|
type Logger interface {
|
|
// Debug logs a message at DEBUG level.
|
|
Debug(msg string, args ...any)
|
|
// Info logs a message at INFO level.
|
|
Info(msg string, args ...any)
|
|
// Warn logs a message at WARN level.
|
|
Warn(msg string, args ...any)
|
|
// Error logs a message at ERROR level. err may be nil.
|
|
// Implementations should detect errs.CodedError and errs.ContextualError
|
|
// and append their fields automatically to the log record.
|
|
Error(msg string, err error, args ...any)
|
|
// With returns a new Logger with the given key-value attributes pre-attached
|
|
// to every subsequent log record produced by the returned logger.
|
|
With(args ...any) Logger
|
|
// WithContext returns a new Logger enriched with request-scoped fields stored
|
|
// in ctx. Safe to call with a nil context — returns the receiver unchanged.
|
|
WithContext(ctx context.Context) Logger
|
|
}
|