-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
78 lines (52 loc) · 1.3 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
package main
import (
"embed"
_ "embed"
"fmt"
"net/http"
"path"
"github.com/gin-gonic/gin"
)
var router *gin.Engine
//go:embed assets/*
var staticFS embed.FS
func init() {
router = gin.Default()
// de, err := tem.ReadDir("assets")
// fmt.Println(">>", err)
// for k, v := range de {
// fs, _ := v.Info()
// fmt.Println(k, v.Name(), fs.Name(), fs.Size())
// }
//gin.SetMode(gin.ReleaseMode) //
//fmt.Println(path.Join("/assets/", "/resources"))
}
func main() {
//gin.HandlerFunc
router.LoadHTMLGlob("template/*")
//http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.FS(tem))))
//fs := http.FileServer(tem)
//router.StaticFS("/resources", http.FS(tem))
router.GET("/:foldername/*filepath", func(c *gin.Context) {
fmt.Println("folder:", c.Param("foldername"))
for key, val := range c.Params {
fmt.Println(key, "==", val)
}
c.FileFromFS(path.Join("/assets/", c.Request.URL.Path), http.FS(staticFS))
})
router.GET("/", func(c *gin.Context) {
c.HTML(http.StatusOK, "index.gohtml", gin.H{"title": "Hello world"})
})
router.GET("/about", Aboutpage)
router.Run(":8080")
}
func Aboutpage(c *gin.Context) {
data := struct {
Title string
Page string
}{
Title: "About us",
Page: "About",
}
c.HTML(http.StatusOK, "about.gohtml", data)
}