feat(wip): node management #70

This commit is contained in:
0xJacky 2023-05-14 22:39:09 +08:00
parent 3ed9ff1a19
commit 47ea62adb2
No known key found for this signature in database
GPG key ID: B6E4A6E4A561BAF0
41 changed files with 1932 additions and 482 deletions

35
server/api/node.go Normal file
View file

@ -0,0 +1,35 @@
package api
import (
"github.com/0xJacky/Nginx-UI/server/service"
"github.com/gin-gonic/gin"
"github.com/shirou/gopsutil/v3/cpu"
"net/http"
)
func GetCurrentNode(c *gin.Context) {
if _, ok := c.Get("NodeSecret"); !ok {
c.JSON(http.StatusNotAcceptable, gin.H{
"message": "node secret not exist",
})
return
}
runtimeInfo, err := service.GetRuntimeInfo()
if err != nil {
ErrHandler(c, err)
return
}
cpuInfo, _ := cpu.Info()
memory, _ := getMemoryStat()
ver, _ := service.GetCurrentVersion()
c.JSON(http.StatusOK, gin.H{
"request_node_secret": c.MustGet("NodeSecret"),
"node_runtime_info": runtimeInfo,
"cpu_num": len(cpuInfo),
"memory_total": memory.Total,
"version": ver.Version,
})
}