-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.go
More file actions
63 lines (54 loc) · 1.93 KB
/
main.go
File metadata and controls
63 lines (54 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* Everato - Modern Event Management Platform
*
* This is the main entry point for the Everato application.
* It initializes configuration, runs database migrations, and starts the HTTP server.
*/
package main
import (
"github.com/dtg-lucifer/everato/config"
"github.com/dtg-lucifer/everato/pkg"
"github.com/joho/godotenv"
)
// main is the application's entry point. It performs the following operations:
// - 1. Loads environment variables from .env file
// - 2. Loads application configuration from config.yaml
// - 3. Runs database migrations to ensure schema is up-to-date
// - 4. Initializes and starts the HTTP server
func main() {
logger := pkg.NewLogger()
// Load environment variables from .env file
// Continues execution even if .env file is not found
if err := godotenv.Load(); err != nil {
logger.Error("Error loading the .env file, falling back to config.yaml and local env")
}
// Load application configuration
cfg, err := config.NewConfig("config.yaml")
if err != nil {
logger.Error("Error loading configuration", "err", err.Error())
panic(err)
}
// Print the configuration for debugging purposes
logger.Info("Configuration loaded successfully:")
config.PrettyPrint(cfg)
// Run database migrations to ensure schema is up-to-date
logger.Info("Running migrations...")
if err := MigrateDB(cfg); err != nil {
logger.Error("Error running migrations", "err", err.Error())
panic(err)
}
logger.Info("Migrations completed successfully...")
// Insert the super users data in the database
if err := SuperUserInit(cfg); err != nil {
logger.Error("Error initializing super users", "err", err.Error())
panic(err)
}
logger.Info("Super users initialized successfully...")
// Initialize and configure the HTTP server
server := NewServer(cfg)
// Start the HTTP server - this call is blocking
if err := server.Start(); err != nil {
logger.Error("Error starting the server", "err", err.Error())
panic(err)
}
}