Fix init order. Reformat.

This commit is contained in:
2025-11-20 14:26:27 +01:00
parent 6239e7f19b
commit f7a0954213
2 changed files with 28 additions and 32 deletions

View File

@@ -424,8 +424,8 @@ func run() error {
// Initialize subsystems in dependency order: // Initialize subsystems in dependency order:
// 1. Load environment variables from .env file (contains sensitive configuration) // 1. Load environment variables from .env file (contains sensitive configuration)
// 2. Load configuration from config.json (may reference environment variables) // 2. Load configuration from config.json (may reference environment variables)
// 3. Initialize database connection (requires config for connection string) // 3. Handle database migration commands if requested
// 4. Handle database commands if requested (requires active database connection) // 4. Initialize database connection (requires config for connection string)
// 5. Handle user commands if requested (requires database and authentication config) // 5. Handle user commands if requested (requires database and authentication config)
// 6. Initialize subsystems like archive and metrics (require config and database) // 6. Initialize subsystems like archive and metrics (require config and database)
@@ -438,13 +438,13 @@ func run() error {
return err return err
} }
// Initialize database // Handle database migration (migrate, revert, force)
if err := initDatabase(); err != nil { if err := handleDatabaseCommands(); err != nil {
return err return err
} }
// Handle database commands (migrate, revert, force) // Initialize database
if err := handleDatabaseCommands(); err != nil { if err := initDatabase(); err != nil {
return err return err
} }
@@ -458,7 +458,7 @@ func run() error {
return err return err
} }
// Start server if requested // Exit if start server is not requested
if !flagServer { if !flagServer {
cclog.Exit("No errors, server flag not set. Exiting cc-backend.") cclog.Exit("No errors, server flag not set. Exiting cc-backend.")
} }
@@ -476,4 +476,3 @@ func main() {
os.Exit(1) os.Exit(1)
} }
} }

View File

@@ -39,9 +39,7 @@ import (
httpSwagger "github.com/swaggo/http-swagger" httpSwagger "github.com/swaggo/http-swagger"
) )
var ( var buildInfo web.Build
buildInfo web.Build
)
// Environment variable names // Environment variable names
const ( const (
@@ -270,7 +268,6 @@ func (s *Server) init() error {
handlers.AllowedMethods([]string{"GET", "POST", "HEAD", "OPTIONS"}), handlers.AllowedMethods([]string{"GET", "POST", "HEAD", "OPTIONS"}),
handlers.AllowedOrigins([]string{"*"}))) handlers.AllowedOrigins([]string{"*"})))
return nil return nil
} }