Documentation
¶
Index ¶
- func Run(logger *slog.Logger, configLoader func(target interface{}) error, ...) error
- type Option
- func WithContext(ctx context.Context) Option
- func WithManagerOptions(opts ...modulex.ManagerOption) Option
- func WithPostStop(fn func(context.Context) error) Option
- func WithPreStop(fn func(context.Context) error) Option
- func WithSetup(fn func(*modulex.Manager) error) Option
- func WithShutdownTimeout(d time.Duration) Option
- func WithSignals(sig ...os.Signal) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Run ¶
func Run(logger *slog.Logger, configLoader func(target interface{}) error, modules []modulex.Module, opts ...Option) error
Run constructs a modulex.Manager, registers modules, and drives the full Init -> Start -> wait-for-shutdown -> Stop lifecycle. A caller with shutdown steps of its own to sequence around StopModules (e.g. an application-level Shutdown before it, or a tracer provider's Shutdown after it) should use WithPreStop/WithPostStop rather than reimplementing this lifecycle by hand.
Types ¶
type Option ¶
type Option func(*options)
Option configures Run.
func WithContext ¶
WithContext sets the base context Run derives its signal-aware lifecycle context from. Defaults to context.Background().
func WithManagerOptions ¶
func WithManagerOptions(opts ...modulex.ManagerOption) Option
WithManagerOptions passes additional modulex.ManagerOption values through to modulex.NewManager.
func WithPostStop ¶ added in v0.8.0
WithPostStop registers a hook that runs immediately after modulex.Manager.StopModules, sharing its shutdown-timeout context. Hooks run in registration order, and run even if StopModules or an earlier hook returned an error, so cleanup of resources set up outside the Manager (e.g. shutting down a tracer provider) is never skipped. All errors are joined into Run's return value.
The hook also runs if InitModules or StartModules fails and Run exits early, since the same pre-stop -> StopModules -> post-stop sequence is used for that cleanup path. The hook must not assume any module or Start-phase state was fully initialized when this happens.
func WithPreStop ¶ added in v0.8.0
WithPreStop registers a hook that runs immediately before modulex.Manager.StopModules, sharing its shutdown-timeout context. Hooks run in registration order. A caller with domain shutdown logic that must complete before modules stop (e.g. draining in-flight requests) should register it here rather than hand-rolling a shutdown sequence around Run. An error does not stop StopModules or any remaining hooks from running; all errors are joined into Run's return value.
The hook also runs if InitModules or StartModules fails and Run exits early, since the same pre-stop -> StopModules -> post-stop sequence is used for that cleanup path. The hook must not assume any module or Start-phase state was fully initialized when this happens.
func WithSetup ¶
WithSetup registers a hook that runs against the constructed Manager after NewManager but before modules are registered and initialized.
func WithShutdownTimeout ¶
WithShutdownTimeout bounds the final StopModules call. Defaults to 15 seconds.
func WithSignals ¶
WithSignals overrides the OS signals that trigger shutdown. Defaults to os.Interrupt and syscall.SIGTERM.