-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
executable file
·47 lines (34 loc) · 996 Bytes
/
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
package main
import (
"app/config"
"app/routes"
"app/views"
"runtime"
"github.com/gin-contrib/static"
"github.com/gin-gonic/gin"
"os"
)
func main() {
//set mode
gin.SetMode(os.Getenv("APP_MODE")) //Caution: You must put the mode to "gin.ReleaseMode" when using in production
//set the number of CPU processor will be used
runtime.GOMAXPROCS(runtime.NumCPU())
//instantiate route
router := gin.Default()
//initialize session
router.Use(config.InitializeSession())
//initialize the routes
routes.InitRoutes(*router)
//route not found response
router.NoRoute(func(c *gin.Context) {
message := map[string]interface{}{"message": "The requested uri is not valid!", "code": 4004}
c.JSON(404, gin.H{"status": 404, "error": message})
return
})
//serve static files
router.Use(static.Serve("/", static.LocalFile("./public", true)))
//load multiple templates
router.HTMLRender = views.LoadTemplates()
//start the server
router.Run(":" + os.Getenv("APP_PORT"))
}