-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
81 lines (71 loc) · 1.5 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
package main
import (
"log"
"strconv"
helmet "github.com/danielkov/gin-helmet"
config "github.com/firmanJS/boilerplate-gin/config"
route "github.com/firmanJS/boilerplate-gin/route"
"github.com/gin-contrib/cors"
"github.com/gin-contrib/gzip"
"github.com/gin-gonic/gin"
)
func main() {
/**
@description Setup Server
*/
config, err := config.NewConfig()
if err != nil {
log.Fatal(err)
}
/**
@description Setup Server
*/
router := SetupRouter()
/**
@description Run Server
*/
log.Fatal(router.Run(":" + strconv.Itoa(config.GO_PORT)))
}
func SetupRouter() *gin.Engine {
/*
@description Setup Database Connection
*/
db := config.Connection()
/*
@description Init Router
*/
router := gin.Default()
/*
@description Setup Mode Application
*/
config, err := config.NewConfig()
if err != nil {
log.Fatal(err)
}
if config.GO_ENV != "production" && config.GO_ENV != "test" {
gin.SetMode(gin.DebugMode)
} else if config.GO_ENV == "test" {
gin.SetMode(gin.TestMode)
} else {
gin.SetMode(gin.ReleaseMode)
}
/*
@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.InitAuthRoutes(db, router)
route.InitProductRoutes(db, router)
route.InitCategoryRoutes(db, router)
route.InitRoute(router)
return router
}