Documentation
¶
Overview ¶
Package slush provides a guarded service locator with cryptographic access control.
Services are registered by interface type and retrieved via context-aware lookups. Guards control access to services, enabling cryptographic validation through external packages like sctx.
Basic usage:
// Register a service
slush.Register[Database](db).
Guard(sctx.RequireClaim("db:access"))
// Retrieve in handler
db, err := slush.Use[Database](ctx)
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("slush: service not registered") ErrAccessDenied = errors.New("slush: access denied") )
Sentinel errors.
var ( SignalRegistered = capitan.NewSignal("slush.registered", "Service registered") SignalAccessed = capitan.NewSignal("slush.accessed", "Service accessed") SignalDenied = capitan.NewSignal("slush.denied", "Service access denied") SignalNotFound = capitan.NewSignal("slush.not_found", "Service not found") )
Capitan signals for service lifecycle events.
var ( KeyInterface = capitan.NewStringKey("interface") KeyImpl = capitan.NewStringKey("impl") KeyError = capitan.NewStringKey("error") )
Capitan keys for event fields.
var ErrInvalidKey = errors.New("slush: invalid key")
ErrInvalidKey is returned when an invalid key is provided.
Functions ¶
func Freeze ¶
func Freeze(k Key)
Freeze prevents further service registration. Panics if key is invalid.
Types ¶
type Guard ¶
Guard validates context before service access. Return nil to permit access, or an error to deny.
type Handle ¶
type Handle[T any] struct { // contains filtered or unexported fields }
Handle configures access control for a registered service.
type Key ¶
type Key struct {
// contains filtered or unexported fields
}
Key grants the capability to register services. Only obtainable via Start(); the unexported inner pointer prevents forgery.
type ServiceInfo ¶
type ServiceInfo struct {
Interface string // Interface FQDN (the lookup key)
Impl string // Implementation FQDN
Metadata sentinel.Metadata // Sentinel metadata from cache
GuardCount int // Number of guards configured
}
ServiceInfo describes a registered service for enumeration.
func Services ¶
func Services(k Key) ([]ServiceInfo, error)
Services returns information about all registered services. Metadata is populated from sentinel's cache via Lookup. Returns ErrInvalidKey if the key is invalid.