mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 10:58:35 +08:00
【升级go 1.18】
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/kakuilan/kgo"
|
||||
@@ -21,7 +22,7 @@ const (
|
||||
)
|
||||
|
||||
func (s *System) ServerInfo(g *gin.Context) {
|
||||
osDic := make(map[string]interface{}, 0)
|
||||
osDic := make(map[string]any, 0)
|
||||
osDic["goOs"] = runtime.GOOS
|
||||
osDic["arch"] = runtime.GOARCH
|
||||
osDic["mem"] = runtime.MemProfileRate
|
||||
@@ -29,26 +30,23 @@ func (s *System) ServerInfo(g *gin.Context) {
|
||||
osDic["version"] = runtime.Version()
|
||||
osDic["numGoroutine"] = runtime.NumGoroutine()
|
||||
|
||||
used, free, total := kgo.KOS.DiskUsage("/")
|
||||
diskDic := make(map[string]interface{}, 0)
|
||||
diskDic["total"] = total / GB
|
||||
diskDic["free"] = free / GB
|
||||
diskDic["used"] = used / GB
|
||||
diskDic["progress"] = int64((float64(used) / float64(total)) * 100)
|
||||
info := kgo.KOS.GetSystemInfo()
|
||||
diskDic := make(map[string]any, 0)
|
||||
diskDic["total"] = info.DiskTotal / GB
|
||||
diskDic["free"] = info.DiskFree / GB
|
||||
diskDic["used"] = info.DiskUsed / GB
|
||||
diskDic["progress"] = int64((float64(info.DiskUsed) / float64(info.DiskTotal)) * 100)
|
||||
|
||||
used2, free2, total2 := kgo.KOS.MemoryUsage(true)
|
||||
memDic := make(map[string]interface{}, 0)
|
||||
memDic["total"] = total2 / GB
|
||||
memDic["used"] = used2 / GB
|
||||
memDic["free"] = free2 / GB
|
||||
memDic["progress"] = int64((float64(used2) / float64(total2)) * 100)
|
||||
memDic := make(map[string]any, 0)
|
||||
memDic["total"] = info.MemTotal / GB
|
||||
memDic["used"] = info.MemUsed / GB
|
||||
memDic["free"] = info.MemFree / GB
|
||||
memDic["progress"] = int64((float64(info.MemUsed) / float64(info.MemTotal)) * 100)
|
||||
|
||||
cpuDic := make(map[string]interface{}, 0)
|
||||
used3, idle, total3 := kgo.KOS.CpuUsage()
|
||||
cpuDic["total"] = total3 / GB
|
||||
cpuDic["used"] = used3 / GB
|
||||
cpuDic["free"] = idle / GB
|
||||
cpuDic["progress"] = int64((float64(used3) / float64(total3)) * 100)
|
||||
cpuDic := make(map[string]any, 0)
|
||||
cpuDic["num"] = info.CpuNum
|
||||
cpuDic["used"] = fmt.Sprintf("%.2f", info.CpuUser*100)
|
||||
cpuDic["free"] = fmt.Sprintf("%.2f", info.CpuFree*100)
|
||||
|
||||
g.JSON(http.StatusOK, gin.H{
|
||||
"code": 200,
|
||||
@@ -63,19 +61,19 @@ func (s *System) ServerInfo(g *gin.Context) {
|
||||
func (s *System) ConnectWs(g *gin.Context) {
|
||||
wsConn, err := ws.Upgrader.Upgrade(g.Writer, g.Request, nil)
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
wsConn.WriteMessage(websocket.TextMessage, []byte(err.(error).Error()))
|
||||
if err := recover(); &err != nil {
|
||||
wsConn.WriteMessage(websocket.TextMessage, []byte(fmt.Sprintf("websocket 失败: %v", err)))
|
||||
wsConn.Close()
|
||||
}
|
||||
}()
|
||||
|
||||
if err != nil {
|
||||
panic(biz.NewBizErr("升级websocket失败"))
|
||||
panic(any(biz.NewBizErr("升级websocket失败")))
|
||||
}
|
||||
// 权限校验
|
||||
rc := ctx.NewReqCtxWithGin(g)
|
||||
if err = ctx.PermissionHandler(rc); err != nil {
|
||||
panic(biz.NewBizErr("没有权限"))
|
||||
panic(any(biz.NewBizErr("没有权限")))
|
||||
}
|
||||
|
||||
// 登录账号信息
|
||||
|
||||
Reference in New Issue
Block a user