package main import ( "log" "gobeyhan/app/routes" "gobeyhan/config" "gobeyhan/database" "github.com/gin-gonic/gin" swaggerFiles "github.com/swaggo/files" ginSwagger "github.com/swaggo/gin-swagger" _ "gobeyhan/docs" // Swagger docs ) // @title Beyhan Backend API // @version 2.0 // @description Modular REST API with Blog, Account, and Settings apps // @termsOfService http://swagger.io/terms/ // @contact.name API Support // @contact.email support@beyhan.com // @license.name MIT // @license.url https://opensource.org/licenses/MIT // @host localhost:8080 // @BasePath /api/v1 // @securityDefinitions.apikey BearerAuth // @in header // @name Authorization // @description Type "Bearer" followed by a space and JWT token. func main() { // Load configuration config.LoadConfig() // Connect to database database.ConnectDB() // Connect to Redis database.ConnectRedis() if err := database.FlushAll(); err != nil { log.Printf("Warning: Failed to flush Redis cache: %v", err) } // Run migrations in development if config.AppConfig.Env == "development" { if err := database.Migrate(database.DB); err != nil { log.Fatalf("Migration failed: %v", err) } log.Println("Migration complete") } // Initialize Gin if config.AppConfig.Env == "production" { gin.SetMode(gin.ReleaseMode) } r := gin.Default() // Swagger endpoint r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) // Setup routes routes.SetupRoutes(r) // Start server port := config.AppConfig.Port if port == "" { port = "8080" } log.Printf("🚀 Server starting on port %s", port) log.Printf("📚 Swagger UI: http://localhost:%s/swagger/index.html", port) log.Printf("🌐 API Base: http://localhost:%s/api/v1", port) if err := r.Run(":" + port); err != nil { log.Fatalf("Failed to start server: %v", err) } }