Skip to content

Commit

Permalink
add title config
Browse files Browse the repository at this point in the history
  • Loading branch information
kzw200015 committed Jul 4, 2021
1 parent 8410082 commit 46932c9
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
### 服务端
配置文件`config.yml`
```
title: 服务器监控
port: 8080
token: passwd
nodes:
Expand Down
2 changes: 1 addition & 1 deletion assets/frontend
1 change: 1 addition & 0 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 4 additions & 0 deletions server/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions server/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 46932c9

Please sign in to comment.