golazy.dev
–
golazy.dev
/
lazydeps
Index
|
Files
package lazydeps ¶
import "golazy.dev/lazydeps"
Constants ¶
const LazyDevDependenciesPath ¶
const LazyDevDependenciesPath = "/dependencies"
const LazyDevDependencyShutdownEventsPath ¶
const LazyDevDependencyShutdownEventsPath = "/dependencies/shutdown/events"
const LazyDevDependencyShutdownPath ¶
const LazyDevDependencyShutdownPath = "/dependencies/shutdown"
Functions ¶
func RegisterLazyDevHandlers ¶
RegisterLazyDevHandlers registers dependency graph inspection endpoints.
func RegisterLazyDevHandlers(controlPlane *lazycontrolplane.ControlPlane, dependencies *Scope, opts ...LazyDevOption)
Types ¶
type Edge ¶
type Edge struct {
From string `json:"from"`
To string `json:"to"`
}
type Func ¶
type Func[T any] func(context.Context) (context.Context, T, error, context.CancelFunc)
type Graph ¶
type Graph struct {
Nodes []string `json:"nodes"`
Edges []Edge `json:"edges"`
}
type LazyDevOption ¶
type LazyDevOption func(*lazyDevOptions)
func WithLazyDevRuntime ¶
WithLazyDevRuntime lets lazydev dependency handlers report readiness, active requests, and active connections while simulating shutdown.
func WithLazyDevRuntime(runtime LazyDevRuntime) LazyDevOption
type LazyDevRuntime ¶
LazyDevRuntime reports application runtime state to dependency development handlers.
type LazyDevRuntime interface {
SetDraining(bool)
Draining() bool
ActiveRequests() int64
ActiveConnections() int64
}
type LazyDevShutdownNode ¶
type LazyDevShutdownNode struct {
Name string `json:"name"`
State string `json:"state"`
}
type LazyDevShutdownState ¶
type LazyDevShutdownState struct {
Graph Graph `json:"graph"`
Ready bool `json:"ready"`
ReadyStatus int `json:"ready_status"`
ReadyText string `json:"ready_text"`
ActiveRequests int64 `json:"active_requests"`
ActiveConnections int64 `json:"active_connections"`
Running bool `json:"running"`
Phase string `json:"phase"`
Message string `json:"message"`
Nodes []LazyDevShutdownNode `json:"nodes"`
Error string `json:"error,omitempty"`
}
type Option ¶
type Option func(*Scope)
func WithLogger ¶
func WithLogger(logger *slog.Logger) Option
type Ref ¶
type Ref[T any] struct {
// contains filtered or unexported fields
}
func Service[T any] ¶
func Service[T any](u *Scope, name string, fn Func[T]) (Ref[T], error)
func (r Ref[T]) Use ¶
func (r Ref[T]) Use() T
type Scope ¶
type Scope struct {
// contains filtered or unexported fields
}
func New ¶
func New(ctx context.Context, opts ...Option) *Scope
func (u *Scope) Context ¶
func (u *Scope) Context() context.Context
func (u *Scope) Graph ¶
func (u *Scope) Graph() Graph
func (u *Scope) SetContext ¶
func (u *Scope) SetContext(ctx context.Context)
func (u *Scope) Shutdown ¶
func (u *Scope) Shutdown(ctx context.Context, reason string) error
Package lazydeps initializes application services, records how they depend on each other, and shuts them down in dependency-safe order.
A Scope is the dependency container for one application process. It is not a service locator for request handlers; it is used during application startup to create long-lived services, attach those services to the application context, and remember the graph that was observed while each initializer ran. When the application shuts down, dependents are stopped before the services they use.
Service runs one initializer in the scope and returns a typed Ref. The Ref is how another initializer says that it needs the service. Calling Ref.Use inside another Service initializer returns the wrapped value and records an edge from the current service to the referenced service. Calling Use after startup is a programming error because lazydeps would no longer know which service is declaring the dependency.
The common GoLazy path is through lazyapp.Config.Dependencies. lazyapp creates the Scope, passes it to the application's Dependencies function, stores the final Scope on lazyapp.App.Dependencies, and continues building routes, renderers, jobs, SEO, and other application systems with the context returned by Scope.Context. Initializers normally return a derived context containing typed context values for packages such as lazycontroller handlers, lazyjobs configuration, or application services that run outside request handling.
lazydeps also has development-only control-plane handlers. In lazydev builds, lazyapp registers them on the lazycontrolplane.ControlPlane, so the development panel can inspect GET /dependencies and run the shutdown simulation endpoints. Applications usually should not call RegisterLazyDevHandlers directly unless they are assembling a custom control-plane outside lazyapp.
The package can also be used without lazyapp when a small server or worker wants typed startup services plus ordered cleanup. Create a Scope with New, call Service for each long-lived dependency, use Ref.Use inside dependent initializers, then call Scope.Shutdown when the process is draining.