feat: add main application entry point
- Add main.go with Fiber web server setup - Include database initialization and admin user setup - Add middleware configuration (logging, request ID, health check) - Add Swagger documentation integration - Configure server to listen on port 8000 - Include proper error handling and graceful shutdown
This commit is contained in:
46
main.go
Normal file
46
main.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"git.secnex.io/secnex/idp-api/db"
|
||||
"git.secnex.io/secnex/idp-api/middlewares"
|
||||
"git.secnex.io/secnex/idp-api/routes"
|
||||
"git.secnex.io/secnex/idp-api/utils"
|
||||
"github.com/gofiber/contrib/swagger"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
"github.com/gofiber/fiber/v2/middleware/healthcheck"
|
||||
"github.com/gofiber/fiber/v2/middleware/logger"
|
||||
"github.com/gofiber/fiber/v2/middleware/requestid"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := db.InitializeDB(); err != nil {
|
||||
log.Fatalf("Failed to initialize database: %v", err)
|
||||
}
|
||||
defer db.CloseDB()
|
||||
|
||||
utils.CheckAdminUser()
|
||||
|
||||
app := fiber.New()
|
||||
|
||||
swaggerCfg := swagger.Config{
|
||||
BasePath: "/",
|
||||
FilePath: "./docs/swagger.json",
|
||||
Path: "/docs/swagger",
|
||||
Title: "Swagger API Docs",
|
||||
}
|
||||
|
||||
app.Use(
|
||||
logger.New(),
|
||||
requestid.New(),
|
||||
healthcheck.New(),
|
||||
swagger.New(swaggerCfg),
|
||||
middlewares.DatabaseMiddleware(), // Add database middleware
|
||||
)
|
||||
|
||||
routes.SetupRoutes(app)
|
||||
|
||||
if err := app.Listen(":8000"); err != nil {
|
||||
log.Fatalf("Failed to start server: %v", err)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user