-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (43 loc) · 1.02 KB
/
main.go
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
package main
import (
"auth-service/config"
"auth-service/config/database"
"auth-service/routers"
"log"
"os"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/healthcheck"
"github.com/gofiber/fiber/v2/middleware/logger"
)
func main() {
config.Init()
app := fiber.New(fiber.Config{
Prefork: true,
})
if !app.Config().Prefork {
database.InitGlobalDB()
}
// Middleware DB (Hanya berguna untuk Prefork)
app.Use(database.DBMiddleware())
app.Use(logger.New())
app.Use(healthcheck.New(healthcheck.Config{
LivenessProbe: func(c *fiber.Ctx) bool {
return true
},
LivenessEndpoint: "/",
}))
app.Use(cors.New(cors.Config{
AllowOrigins: "*",
AllowHeaders: "*",
AllowMethods:"GET,POST,OPTIONS,PUT,DELETE,PATCH",
}))
routers.HandleRouter(app)
port := os.Getenv("PORT")
if port == "" {
port = "9000"
}
log.Print("Routed to port " + port, " ", fiber.IsChild())
log.Fatal(app.Listen(":" + port))
defer database.CloseDBConnection()
}