-
Notifications
You must be signed in to change notification settings - Fork 52
/
main.go
63 lines (58 loc) · 1.31 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
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/restuwahyu13/gin-rest-api/configs"
route "github.com/restuwahyu13/gin-rest-api/routes"
util "github.com/restuwahyu13/gin-rest-api/utils"
)
func main() {
/**
@description Setup Server
*/
router := SetupRouter()
/**
@description Run Server
*/
log.Fatal(router.Run(":" + util.GodotEnv("GO_PORT")))
}
func SetupRouter() *gin.Engine {
/**
@description Setup Database Connection
*/
db := config.Connection()
/**
@description Init Router
*/
router := gin.Default()
/**
@description Setup Mode Application
*/
if util.GodotEnv("GO_ENV") != "production" && util.GodotEnv("GO_ENV") != "test" {
gin.SetMode(gin.DebugMode)
} else if util.GodotEnv("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.InitStudentRoutes(db, router)
return router
}