-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (44 loc) · 1.13 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
52
53
54
55
56
57
package main
import (
"qna-management/configs"
"qna-management/routes"
"qna-management/utils"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
func main() {
// Get the logger instance
log := utils.GetLogger()
// --------- Start application ----------
log.Info("Starting the application...")
// Setup router
router := SetupRouter()
// Run server
log.Fatal(router.Run(":" + utils.GodotEnv("GO_PORT")))
// --------- End program ----------
log.Info("Ending the application...")
}
func SetupRouter() *gin.Engine {
// Setup database connection
db := configs.Connection()
// Init router
router := gin.Default()
// Setup mode application
if utils.GodotEnv("GO_ENV") != "production" && utils.GodotEnv("GO_ENV") != "test" {
gin.SetMode(gin.DebugMode)
} else if utils.GodotEnv("GO_ENV") == "test" {
gin.SetMode(gin.TestMode)
} else {
gin.SetMode(gin.ReleaseMode)
}
// Setup Middleware
router.Use(cors.New(cors.Config{
AllowOrigins: []string{"*"},
AllowMethods: []string{"*"},
AllowHeaders: []string{"*"},
AllowWildcard: true,
}))
// Init all routes
routes.InitRoutes(db, router)
return router
}