app

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package app provides the core application framework for the MDW API Platform. It handles application lifecycle, module registration, and service orchestration.

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

func New() (*App, error)

New creates a new application instance with all necessary dependencies. It initializes configuration, logging, database, and HTTP server components.

func (*App) RegisterModule

func (a *App) RegisterModule(module Module) error

RegisterModule registers a new module with the application. It adds the module to the registry for initialization and route registration.

func (*App) Run

func (a *App) Run() error

Run starts the application and blocks until a shutdown signal is received. It handles graceful shutdown with a timeout.

func (*App) Shutdown

func (a *App) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the application with the given context. It closes database connections, messaging client, and stops the HTTP server.

type Module

type Module interface {
	Name() string
	Init(deps *ModuleDeps) error
	RegisterRoutes(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
}

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.

Jump to

Keyboard shortcuts

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