package main import ( "errors" "fmt" "os" "github.com/joho/godotenv" "lst.net/internal/db" "lst.net/internal/router" "lst.net/pkg/logger" ) func main() { log := logger.New() if os.Getenv("RUNNING_IN_DOCKER") != "true" { err := godotenv.Load("../.env") if err != nil { log := logger.New() log.Info("Warning: .env file not found (ok in Docker/production)", "system", map[string]interface{}{}) } } // Initialize DB if _, err := db.InitDB(); err != nil { log.Panic("Database intialize failed", "db", map[string]interface{}{ "error": err.Error(), "casue": errors.Unwrap(err), "timeout": "30s", "details": fmt.Sprintf("%+v", err), // Full stack trace if available }) } defer func() { if r := recover(); r != nil { sqlDB, _ := db.DB.DB() sqlDB.Close() log.Error("Recovered from panic during DB shutdown", "db", map[string]interface{}{ "panic": r, }) } }() // long lived process like ocp running all the time should go here and base the db struct over. // go ocp.MonitorPrinters // go notifcations.Processor // Set basePath dynamically basePath := "/" if os.Getenv("APP_ENV") != "production" { basePath = "/lst" // Dev only } fmt.Println("Welcome to lst backend where all the fun happens.") // Init Gin router and pass DB to services r := router.Setup(db.DB, basePath, log) // get the server port port := "8080" if os.Getenv("VITE_SERVER_PORT") != "" { port = os.Getenv("VITE_SERVER_PORT") } if err := r.Run(":" + port); err != nil { log := logger.New() log.Panic("Server failed to start", "system", map[string]interface{}{ "error": err, }) } }