golazy.dev golazy.dev / lazydeps Index | Files

package lazydeps

import "golazy.dev/lazydeps"

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.

Constants

Functions

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 LazyDevRuntime

LazyDevRuntime reports application runtime state to dependency development handlers.

type LazyDevRuntime interface {
	SetDraining(bool)
	Draining() bool
	ActiveRequests() int64
	ActiveConnections() int64
}

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"`
}