-
Notifications
You must be signed in to change notification settings - Fork 325
/
materials.go
80 lines (71 loc) · 1.85 KB
/
materials.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
79
80
// 学习资料页面
package routes
import (
"encoding/json"
"net/http"
"github.com/axiaoxin-com/investool/statics"
"github.com/axiaoxin-com/investool/version"
"github.com/axiaoxin-com/logging"
"github.com/gin-gonic/gin"
"github.com/spf13/viper"
)
// MaterialItem 学习资料具体信息
type MaterialItem struct {
Name string `json:"name"`
DownloadURL string `json:"download_url"`
Desc string `json:"desc"`
}
// MaterialSeries 某一个系列的资料
//
// {
// "飙股在线等": [
// MaterialItem, ...
// ]
// }
type MaterialSeries map[string][]MaterialItem
// TypedMaterialSeries 对MaterialSeries进行分类,如:视频、电子书等
//
// {
// "videos": [
// MaterialSeries, ...
// ],
// "ebooks": [
// MaterialSeries, ...
// ]
// }
type TypedMaterialSeries map[string][]MaterialSeries
// AllMaterialsList 包含全部资料信息的大JSON列表
// [
//
// TypedMaterialSeries, ...
//
// ]
type AllMaterialsList []TypedMaterialSeries
// MaterialsFilename 资料JSON文件路径
var MaterialsFilename = "materials"
// Materials godoc
func Materials(c *gin.Context) {
data := gin.H{
"Env": viper.GetString("env"),
"HostURL": viper.GetString("server.host_url"),
"Version": version.Version,
"PageTitle": "InvesTool | 资料",
}
f, err := statics.Files.ReadFile(MaterialsFilename)
if err != nil {
logging.Errorf(c, "Read MaterialsFilename:%v err:%v", MaterialsFilename, err)
data["Error"] = err
c.HTML(http.StatusOK, "materials.html", data)
return
}
var mlist AllMaterialsList
if err := json.Unmarshal(f, &mlist); err != nil {
logging.Errorf(c, "json Unmarshal AllMaterialsList err:%v", err)
data["Error"] = err
c.HTML(http.StatusOK, "materials.html", data)
return
}
data["AllMaterialsList"] = mlist
c.HTML(http.StatusOK, "materials.html", data)
return
}