From 46932c9e017355383e0c1a2d8f1c2ba7cdc28572 Mon Sep 17 00:00:00 2001 From: kzw200015 Date: Sun, 4 Jul 2021 19:55:37 +0800 Subject: [PATCH] add title config --- README.md | 1 + assets/frontend | 2 +- server/config/config.go | 1 + server/handlers/handlers.go | 4 ++++ server/routes/routes.go | 1 + 5 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 18b562a..a29b5a4 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ ### 服务端 配置文件`config.yml` ``` +title: 服务器监控 port: 8080 token: passwd nodes: diff --git a/assets/frontend b/assets/frontend index 3dc9f6e..9b960ca 160000 --- a/assets/frontend +++ b/assets/frontend @@ -1 +1 @@ -Subproject commit 3dc9f6ee193fec3f09b942bb35974ab835390d1c +Subproject commit 9b960cac02877dfeca59cd5ebaf40af0270872a5 diff --git a/server/config/config.go b/server/config/config.go index 65f49da..f66e799 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -10,6 +10,7 @@ import ( var config Config type Config struct { + Title string `yaml:"title"` Port int `yaml:"port"` Token string `yaml:"token"` Nodes []NodeConfig `yaml:"nodes"` diff --git a/server/handlers/handlers.go b/server/handlers/handlers.go index 60293c5..f47cc39 100644 --- a/server/handlers/handlers.go +++ b/server/handlers/handlers.go @@ -15,6 +15,10 @@ type Node struct { IsAlive bool `json:"is_alive"` } +func HandleGetTitle(c *gin.Context) { + c.String(http.StatusOK, config.Get().Title) +} + func HandleGetNodes(c *gin.Context) { var resp = []Node{} for _, node := range config.Get().Nodes { diff --git a/server/routes/routes.go b/server/routes/routes.go index 3ecc054..65ab0de 100644 --- a/server/routes/routes.go +++ b/server/routes/routes.go @@ -14,6 +14,7 @@ func CreateRouter() *gin.Engine { r.Use(middlewares.HandleErrors()).Use(middlewares.HandleStatics(assets.EFS)) api := r.Group("/api").Use(cors.Default()) { + api.GET("/title", handlers.HandleGetTitle) api.GET("/nodes", handlers.HandleGetNodes) api.GET("/nodes/:id/status", handlers.HandleGetNodeStatus) api.POST("/nodes", gin.BasicAuth(config.GetAuthMap()), middlewares.HandleAlive(), handlers.HandlePostNodeStatus)