-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
84 lines (72 loc) · 1.56 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"log"
helmet "github.com/danielkov/gin-helmet"
"github.com/gin-contrib/cors"
"github.com/gin-contrib/gzip"
"github.com/gin-gonic/gin"
config "github.com/lplanch/test-go-api/configs"
route "github.com/lplanch/test-go-api/routes"
util "github.com/lplanch/test-go-api/utils"
)
func main() {
/**
@description Utils initialisation
*/
util.InitUptime()
/**
@description Setup Server
*/
router := SetupRouter()
/**
@description Run Server
*/
log.Fatal(router.Run(":" + util.GodotEnv("PORT")))
}
func SetupRouter() *gin.Engine {
/**
@description Setup Database Connection
*/
db := config.Connection()
/**
@description Init Router
*/
router := gin.Default()
router.UseRawPath = true
router.UnescapePathValues = true
/**
@description Setup Mode Application
*/
env_name := util.GodotEnv("RAILWAY_ENVIRONMENT_NAME")
println(env_name)
if env_name == "production" {
gin.SetMode(gin.ReleaseMode)
} else if env_name == "test" {
gin.SetMode(gin.TestMode)
} else {
gin.SetMode(gin.DebugMode)
}
/**
@description Validator Initialization
*/
util.InitValidator()
/**
@description Setup Middleware
*/
router.Use(cors.New(cors.Config{
AllowOrigins: []string{"*"},
AllowMethods: []string{"*"},
AllowHeaders: []string{"*"},
AllowWildcard: true,
}))
router.Use(helmet.Default())
router.Use(gzip.Gzip(gzip.BestCompression))
/**
@description Init All Route
*/
route.InitMiscRoutes(db, router)
route.InitBanlistRoutes(db, router)
route.InitArchetypeRoutes(db, router)
route.InitCardsRoutes(db, router)
return router
}