-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
69 lines (55 loc) · 1.63 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
package main
import (
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"gopkg.in/yaml.v3"
"net/http"
"os"
"strings"
)
type Env struct {
WebsiteTitle string `yaml:"website_title" json:"website_title"`
WebsiteAuthor string `yaml:"website_author" json:"website_author"`
WebsiteDescription string `yaml:"website_description" json:"website_description"`
WebsiteKeywords string `yaml:"website_keywords" json:"website_keywords"`
Logo string `yaml:"logo" json:"logo"`
GithubUsername string `json:"github_username" yaml:"github_username"`
Email string `json:"email" yaml:"email"`
Pay string `json:"pay" yaml:"pay"`
Qq string `json:"qq" yaml:"qq"`
Sites []Site `json:"sites"`
Projects []Project `json:"projects"`
}
type (
Site struct {
Title string `json:"title" yaml:"title"`
Url string `json:"url" yaml:"url"`
Desc string `json:"desc" yaml:"desc"`
}
Project struct {
Title string `json:"title" yaml:"title"`
Url string `json:"url" yaml:"url"`
Desc string `json:"desc" yaml:"desc"`
}
)
var cfg Env
func main() {
gin.SetMode(gin.ReleaseMode)
r := gin.Default()
r.LoadHTMLGlob("templates/*")
r.Static("/static", "./static")
r.GET("/", func(c *gin.Context) {
if _, err := os.Stat("config.yml"); err != nil {
c.JSON(500, fmt.Sprintf("文件 [config.yml] 不存在!"))
c.Abort()
}
content, _ := os.ReadFile("config.yml")
_ = yaml.NewDecoder(strings.NewReader(string(content))).Decode(&cfg)
b, _ := json.Marshal(cfg)
var body map[string]interface{}
_ = json.Unmarshal(b, &body)
c.HTML(http.StatusOK, "index.html", body)
})
_ = r.Run()
}