This commit is contained in:
38
main.go
38
main.go
@@ -5,12 +5,18 @@ import (
|
||||
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Load configuration with environment file precedence
|
||||
config := LoadConfig()
|
||||
|
||||
// Initialize structured logger
|
||||
if err := InitLogger(config); err != nil {
|
||||
log.Fatal("Failed to initialize logger:", err)
|
||||
}
|
||||
|
||||
// Set Gin mode based on configuration
|
||||
gin.SetMode(config.GinMode)
|
||||
|
||||
@@ -19,12 +25,12 @@ func main() {
|
||||
|
||||
// Initialize database with configuration
|
||||
if err := InitDBWithConfig(config); err != nil {
|
||||
log.Fatal("Failed to initialize database :", err)
|
||||
Logger.WithError(err).Fatal("Failed to initialize database")
|
||||
}
|
||||
|
||||
// Create tables
|
||||
if err := CreateTables(); err != nil {
|
||||
log.Fatal("Failed to create tables:", err)
|
||||
Logger.WithError(err).Fatal("Failed to create tables")
|
||||
}
|
||||
|
||||
// Initialize Prometheus metrics
|
||||
@@ -47,6 +53,9 @@ func main() {
|
||||
// Add metrics middleware
|
||||
r.Use(MetricsMiddleware())
|
||||
|
||||
// Add logging middleware
|
||||
r.Use(LoggingMiddleware())
|
||||
|
||||
// Health check endpoint
|
||||
r.GET("/health", func(c *gin.Context) {
|
||||
c.JSON(200, gin.H{"status": "ok"})
|
||||
@@ -88,16 +97,19 @@ func main() {
|
||||
// Start server
|
||||
port := config.Port
|
||||
|
||||
log.Printf("")
|
||||
log.Printf("🚀 Starting Counter Application Server...")
|
||||
log.Printf(" 🌐 Listening on: http://localhost:%s", port)
|
||||
log.Printf(" 📊 Health check: http://localhost:%s/health", port)
|
||||
log.Printf(" 🔗 API endpoint: http://localhost:%s/api/v1", port)
|
||||
log.Printf(" 🎨 Frontend: http://localhost:%s/", port)
|
||||
log.Printf(" 📈 Metrics: http://localhost:%s/metrics", config.MetricsPort)
|
||||
log.Printf("")
|
||||
log.Printf("✅ Server is ready and accepting connections!")
|
||||
log.Printf("")
|
||||
Logger.WithFields(logrus.Fields{
|
||||
"port": port,
|
||||
"metrics_port": config.MetricsPort,
|
||||
"log_dir": config.LogDir,
|
||||
"log_volume": config.LogVolume,
|
||||
}).Info("🚀 Starting Counter Application Server")
|
||||
|
||||
log.Fatal(r.Run(":" + port))
|
||||
Logger.WithFields(logrus.Fields{
|
||||
"health_url": "http://localhost:" + port + "/health",
|
||||
"api_url": "http://localhost:" + port + "/api/v1",
|
||||
"frontend_url": "http://localhost:" + port + "/",
|
||||
"metrics_url": "http://localhost:" + config.MetricsPort + "/metrics",
|
||||
}).Info("✅ Server is ready and accepting connections")
|
||||
|
||||
Logger.Fatal(r.Run(":" + port))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user