- Add fx.Invoke in main.go to force database and HTTP server creation - This ensures all providers execute and their lifecycle hooks are registered - Clean up debug logging statements - Database migrations and HTTP server now start correctly on application startup Fixes issue where database migrations and HTTP server were not starting because FX providers were not being executed (lazy evaluation).
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
// Package main provides the application entry point for the Go Platform.
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
|
|
"git.dcentral.systems/toolz/goplt/internal/di"
|
|
"git.dcentral.systems/toolz/goplt/internal/infra/database"
|
|
"git.dcentral.systems/toolz/goplt/internal/server"
|
|
"git.dcentral.systems/toolz/goplt/pkg/logger"
|
|
"go.uber.org/fx"
|
|
)
|
|
|
|
func main() {
|
|
// Create DI container with lifecycle hooks
|
|
// We need to invoke the HTTP server to ensure all providers execute
|
|
container := di.NewContainer(
|
|
// Invoke lifecycle hooks
|
|
fx.Invoke(di.RegisterLifecycleHooks),
|
|
// Force HTTP server to be created (which triggers all dependencies)
|
|
// This ensures database, health, metrics, etc. are all created
|
|
fx.Invoke(func(srv *server.Server, dbClient *database.Client) {
|
|
// Both server and database are created, hooks are registered
|
|
// This ensures all providers execute
|
|
}),
|
|
)
|
|
|
|
// Create root context
|
|
ctx := context.Background()
|
|
|
|
// Start the application
|
|
if err := container.Start(ctx); err != nil {
|
|
log := logger.GetGlobalLogger()
|
|
if log != nil {
|
|
log.Error("Failed to start application",
|
|
logger.Error(err),
|
|
)
|
|
} else {
|
|
fmt.Fprintf(os.Stderr, "Failed to start application: %v\n", err)
|
|
}
|
|
os.Exit(1)
|
|
}
|
|
}
|