Documentation
¶
Overview ¶
Package app provides an opinionated bootstrap helper for modulex-based services.
Every modulex service entrypoint otherwise hand-writes the same skeleton: construct a Manager, register modules, derive a signal-aware context, drive Init -> Start -> wait -> Stop, and report the first failing step. Run owns that skeleton so main() can stay limited to composing modules and configuration.
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.
Run blocks until the context derived from WithContext (or context.Background() by default) is cancelled or one of the configured shutdown signals (os.Interrupt and syscall.SIGTERM by default) is received, then stops the manager with a bounded timeout. It returns the first error encountered at any step, wrapped with context about which step failed; Run itself never calls os.Exit, so callers remain free to decide how to report the error:
if err := app.Run(logger, configLoader, modules); err != nil {
logger.Error("application failed", slog.Any("error", err))
os.Exit(1)
}
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(). Tests typically pass a cancellable context here instead of relying on OS signals to trigger shutdown.
func WithManagerOptions ¶
func WithManagerOptions(opts ...modulex.ManagerOption) Option
WithManagerOptions passes additional modulex.ManagerOption values through to modulex.NewManager, e.g. WithTracer, WithEventBus, or WithPanicPolicy.
func WithSetup ¶
WithSetup registers a hook that runs against the constructed Manager after NewManager but before modules are registered and initialized. Use this for wiring that must happen before Init, such as registering a Chi router via modulexchi.RegisterRouter.
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.