Documentation
¶
Overview ¶
Package app provides the core application structure and lifecycle management.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App represents the main application instance. It manages the lifecycle and coordination of all application components.
func New ¶
New creates a new application instance with dependencies determined by configuration. It initializes only the services that are configured, failing fast if configured services cannot connect.
func NewWithConfig ¶ added in v0.4.0
NewWithConfig creates a new application instance with the provided config and optional overrides. This factory method allows for dependency injection while maintaining fail-fast behavior.
func (*App) RegisterModule ¶
RegisterModule registers a new module with the application. It adds the module to the registry for initialization and route registration.
type Module ¶
type Module interface {
Name() string
Init(deps *ModuleDeps) error
RegisterRoutes(hr *server.HandlerRegistry, e *echo.Echo)
RegisterMessaging(registry *messaging.Registry)
Shutdown() error
}
Module defines the interface that all application modules must implement. It provides hooks for initialization, route registration, messaging setup, and cleanup.
type ModuleDeps ¶
type ModuleDeps struct {
DB database.Interface
Logger logger.Logger
Messaging messaging.Client
Config *config.Config
}
ModuleDeps contains the dependencies that are injected into each module. It provides access to core services like database, logging, and messaging.
type ModuleRegistry ¶
type ModuleRegistry struct {
// contains filtered or unexported fields
}
ModuleRegistry manages the registration and lifecycle of application modules. It handles module initialization, route registration, messaging setup, and shutdown.
func NewModuleRegistry ¶
func NewModuleRegistry(deps *ModuleDeps) *ModuleRegistry
NewModuleRegistry creates a new module registry with the given dependencies. It initializes an empty registry ready to accept module registrations.
func (*ModuleRegistry) Register ¶
func (r *ModuleRegistry) Register(module Module) error
Register adds a module to the registry and initializes it. It calls the module's Init method with the injected dependencies.
func (*ModuleRegistry) RegisterMessaging ¶
func (r *ModuleRegistry) RegisterMessaging() error
RegisterMessaging calls RegisterMessaging on all registered modules. It should be called after all modules have been registered but before starting the server.
func (*ModuleRegistry) RegisterRoutes ¶
func (r *ModuleRegistry) RegisterRoutes(e *echo.Echo)
RegisterRoutes calls RegisterRoutes on all registered modules. It should be called after all modules have been registered.
func (*ModuleRegistry) Shutdown ¶
func (r *ModuleRegistry) Shutdown() error
Shutdown gracefully shuts down all registered modules. It calls each module's Shutdown method and logs any errors.
type OSSignalHandler ¶ added in v0.4.0
type OSSignalHandler struct{}
OSSignalHandler implements SignalHandler using the real OS signal package
func (*OSSignalHandler) Notify ¶ added in v0.4.0
func (osh *OSSignalHandler) Notify(c chan<- os.Signal, sig ...os.Signal)
func (*OSSignalHandler) WaitForSignal ¶ added in v0.4.0
func (osh *OSSignalHandler) WaitForSignal(c <-chan os.Signal)
type Options ¶ added in v0.4.0
type Options struct {
Database database.Interface
MessagingClient messaging.Client
SignalHandler SignalHandler
TimeoutProvider TimeoutProvider
}
Options contains optional dependencies for creating an App instance
type SignalHandler ¶ added in v0.4.0
type SignalHandler interface {
Notify(c chan<- os.Signal, sig ...os.Signal)
WaitForSignal(c <-chan os.Signal)
}
SignalHandler interface allows for injectable signal handling for testing
type StandardTimeoutProvider ¶ added in v0.4.0
type StandardTimeoutProvider struct{}
StandardTimeoutProvider implements TimeoutProvider using context.WithTimeout
func (*StandardTimeoutProvider) WithTimeout ¶ added in v0.4.0
func (stp *StandardTimeoutProvider) WithTimeout(parent context.Context, timeout time.Duration) (context.Context, context.CancelFunc)
type TimeoutProvider ¶ added in v0.4.0
type TimeoutProvider interface {
WithTimeout(parent context.Context, timeout time.Duration) (context.Context, context.CancelFunc)
}
TimeoutProvider interface allows for injectable timeout creation for testing