Application Bootstrap
Bootstrapping Pipeline
Every Lemmego application starts with a builder pattern in cmd/app/main.go:
func main() {
webApp := app.Configure()
webApp.
WithRoutes(bootstrap.LoadRoutes()).
WithHTTPMiddlewares(bootstrap.LoadHTTPMiddlewares()).
WithMiddlewares(bootstrap.LoadMiddlewares()).
WithCommands(bootstrap.LoadCommands()).
WithProviders(bootstrap.LoadProviders()).
WithErrMap(bootstrap.LoadErrMap()).
Run()
}The app.Configure() function creates a new AppEngine instance using functional options:
app.Configure(
app.WithConfig(config.M{...}),
app.WithRoutes([]RouteCallback{...}),
app.WithProviders([]Provider{...}),
)Boot Order
When Run() is called, the framework initializes in this order:
- Configuration — Config map is set up from
internal/configs/ - Commands — CLI commands are registered
- Events — Middleware, routes, commands, and services events fire
- HTTP Middleware — Global
net/httpmiddleware wraps the router - Providers — All service providers run their
Provide()methods - App Middleware — Application-level middleware is registered
- Routes — Route callbacks register all endpoints
- ErrMap — Error-to-handler mappings are applied
- Server Start — The HTTP server begins listening (or CLI executes)
Run Modes
The application detects whether it’s running as a web server or CLI command:
// Returns true if command-line arguments were provided
a.RunningInConsole()
// Check the environment
a.InProduction()
a.Env("development")If CLI arguments are provided, Run() executes the matching command instead of starting the web server.
Lifecycle Events
The framework fires events at each stage of bootstrapping:
app.ServerStarted // Fired when the HTTP server starts
app.MiddlewareRegistering // Before middleware is registered
app.MiddlewareRegistered // After middleware is registered
app.RoutesRegistering // Before routes are registered
app.RoutesRegistered // After routes are registered
app.CommandsRegistering // Before commands are registered
app.CommandsRegistered // After commands are registered
app.ServicesRegistering // Before services are registered
app.ServicesRegistered // After services are registeredListen to these events to hook into the application lifecycle (see Event System).