-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.go
More file actions
63 lines (54 loc) · 1.32 KB
/
index.go
File metadata and controls
63 lines (54 loc) · 1.32 KB
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 (
"encoding/json"
"fmt"
"html/template"
"net/http"
assetfs "github.com/elazarl/go-bindata-assetfs"
"github.com/gin-contrib/multitemplate"
"github.com/gin-gonic/gin"
)
type ImageItem struct {
ImageThum string
ImageNomal string
}
func main() {
fs := assetfs.AssetFS{
Asset: Asset,
AssetDir: AssetDir,
AssetInfo: AssetInfo,
}
router := gin.Default()
router.StaticFS("/static", &fs)
r := multitemplate.New()
bytes, err := Asset("temp/oldindex.html") // 根据地址获取对应内容
if err != nil {
fmt.Println(err)
return
}
t, err := template.New("index").Parse(string(bytes)) // 比如用于模板处理
fmt.Println(t, err)
r.Add("index", t)
router.HTMLRender = r
router.GET("/image", func(c *gin.Context) {
c.HTML(200, "index", gin.H{})
})
var imageArr []ImageItem
for index := 0; index < 3; index++ {
ii := &ImageItem{"static/img/thumb-2.jpg", "static/img/1-1600.jpg"}
imageArr = append(imageArr, *ii)
}
for index := 0; index < 3; index++ {
i5 := &ImageItem{"static/img/thumb-4.jpg", "static/video/video.mp4"}
imageArr = append(imageArr, *i5)
}
router.GET("/getimagelist", func(c *gin.Context) {
c.JSON(200, gin.H{
"data": func() string {
jsonStr, _ := json.Marshal(imageArr)
return string(jsonStr)
}(),
})
})
http.ListenAndServe(":8888", router)
}