-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (48 loc) · 1.36 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 (
"layoutrender-boilerplate/app"
"layoutrender-boilerplate/config"
"layoutrender-boilerplate/controller"
"layoutrender-boilerplate/repository"
"net/http"
"os"
"strings"
"github.com/gin-gonic/gin"
)
func main() {
env := os.Getenv("ENV")
if env == "" {
panic("ENV cannot be empty")
}
conf := config.NewConfig(".conf", env)
if conf.Mode == "release" {
gin.SetMode(gin.ReleaseMode)
}
homeRepository := repository.Home{}
homeApp := app.NewHomeApp(homeRepository)
homeController := controller.NewHomeController(homeApp)
router := gin.Default()
router.LoadHTMLGlob("public/templates/**/*")
router.GET("/", homeController.HomePage)
router.GET("/static/*path", func(c *gin.Context) {
p := c.Param("path")
file, err := Asset("public/assets" + p)
if err != nil {
c.Status(http.StatusNotFound)
return
}
if strings.Contains(p, ".css") {
c.Writer.Header().Add("Content-Type", "text/css")
} else if strings.Contains(p, ".js") {
c.Writer.Header().Add("Content-Type", "text/javascript")
} else if strings.Contains(p, ".png") {
c.Writer.Header().Add("Content-Type", "image/png")
} else if strings.Contains(p, ".png") {
c.Writer.Header().Add("Content-Type", "image/png")
} else if strings.Contains(p, ".png") {
c.Writer.Header().Add("Content-Type", "image/jpeg")
}
c.Writer.Write(file)
})
router.Run()
}