app

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

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

func WithContext(ctx context.Context) Option

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

func WithPostStop(fn func(context.Context) error) Option

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

func WithPreStop(fn func(context.Context) error) Option

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

func WithSetup(fn func(*modulex.Manager) error) Option

WithSetup registers a hook that runs against the constructed Manager after NewManager but before modules are registered and initialized.

func WithShutdownTimeout

func WithShutdownTimeout(d time.Duration) Option

WithShutdownTimeout bounds the final StopModules call. Defaults to 15 seconds.

func WithSignals

func WithSignals(sig ...os.Signal) Option

WithSignals overrides the OS signals that trigger shutdown. Defaults to os.Interrupt and syscall.SIGTERM.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL