Overview
slush is a guarded service locator for Go. Register services by interface type, configure access guards, and retrieve them with context-aware validation.
The Idea
Service locators have a reputation problem. They hide dependencies and make code harder to reason about. But sometimes you need runtime service discovery—plugins, HTTP handlers, or frameworks where the consumer doesn't control instantiation.
The question: Can we make service lookup explicit about access control?
slush answers by putting guards at the center. Every lookup passes through composable guard functions that validate the request context before returning the service. The registry isn't a bag of services—it's a set of guarded gates.
The Implementation
slush provides:
- Generic registration —
Register[T](impl)stores services by interface type with full type safety - Composable guards —
Handle.Guard(fn)chains access checks that validate context - Context-aware lookup —
Use[T](ctx)runs all guards before returning the service - Service enumeration —
Services()returns metadata for all registered services - Event emission — Lifecycle events via capitan for observability
What It Enables
Cryptographic access control: Combine with sctx for guards that verify token signatures and permissions.
Service introspection: Services() returns sentinel metadata for each implementation, enabling documentation endpoints and ERD generation.
Observability: capitan events on register, access, denied, and not-found for tracing and alerting.
Next Steps
- Quickstart — Install and basic usage
- Concepts — Mental models for services, guards, and handles
- API Reference — Complete function documentation