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:
@@ -63,7 +63,7 @@ func (s *SystemApiApi) GetApiList(rc *ctx.ReqCtx) {
|
||||
apiGroup := rc.GinCtx.Query("apiGroup")
|
||||
api := entity.SysApi{Path: path, Description: description, Method: method, ApiGroup: apiGroup}
|
||||
list, total := s.ApiApp.FindListPage(pageNum, pageSize, api)
|
||||
rc.ResData = map[string]interface{}{
|
||||
rc.ResData = map[string]any{
|
||||
"data": list,
|
||||
"total": total,
|
||||
"pageNum": pageNum,
|
||||
|
||||
@@ -33,7 +33,7 @@ func (p *ConfigApi) GetConfigList(rc *ctx.ReqCtx) {
|
||||
config := entity.SysConfig{ConfigName: configName, ConfigKey: configKey, ConfigType: configType}
|
||||
list, total := p.ConfigApp.FindListPage(pageNum, pageSize, config)
|
||||
|
||||
rc.ResData = map[string]interface{}{
|
||||
rc.ResData = map[string]any{
|
||||
"data": list,
|
||||
"total": total,
|
||||
"pageNum": pageNum,
|
||||
|
||||
@@ -35,7 +35,7 @@ func (m *DeptApi) GetDeptTreeRoleSelect(rc *ctx.ReqCtx) {
|
||||
if roleId != 0 {
|
||||
deptIds = m.RoleApp.GetRoleDeptId(entity.SysRole{RoleId: int64(roleId)})
|
||||
}
|
||||
rc.ResData = map[string]interface{}{
|
||||
rc.ResData = map[string]any{
|
||||
"depts": result,
|
||||
"checkedKeys": deptIds,
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ func (p *DictApi) GetDictTypeList(rc *ctx.ReqCtx) {
|
||||
dictType := rc.GinCtx.Query("dictType")
|
||||
|
||||
list, total := p.DictType.FindListPage(pageNum, pageSize, entity.SysDictType{Status: status, DictName: dictName, DictType: dictType})
|
||||
rc.ResData = map[string]interface{}{
|
||||
rc.ResData = map[string]any{
|
||||
"data": list,
|
||||
"total": total,
|
||||
"pageNum": pageNum,
|
||||
|
||||
@@ -57,7 +57,7 @@ func (m *MenuApi) GetMenuTreeRoleSelect(rc *ctx.ReqCtx) {
|
||||
if roleId != 0 {
|
||||
menuIds = m.RoleApp.GetRoleMeunId(entity.SysRole{RoleId: int64(roleId)})
|
||||
}
|
||||
rc.ResData = map[string]interface{}{
|
||||
rc.ResData = map[string]any{
|
||||
"menus": result,
|
||||
"checkedKeys": menuIds,
|
||||
}
|
||||
@@ -128,7 +128,7 @@ func (m *MenuApi) InsertMenu(rc *ctx.ReqCtx) {
|
||||
m.MenuApp.Insert(menu)
|
||||
permis := m.RoleMenuApp.GetPermis(rc.LoginAccount.RoleId)
|
||||
menus := m.MenuApp.SelectMenuRole(rc.LoginAccount.RoleKey)
|
||||
rc.ResData = map[string]interface{}{
|
||||
rc.ResData = map[string]any{
|
||||
"permissions": permis,
|
||||
"menus": Build(*menus),
|
||||
}
|
||||
@@ -149,7 +149,7 @@ func (m *MenuApi) UpdateMenu(rc *ctx.ReqCtx) {
|
||||
m.MenuApp.Update(menu)
|
||||
permis := m.RoleMenuApp.GetPermis(rc.LoginAccount.RoleId)
|
||||
menus := m.MenuApp.SelectMenuRole(rc.LoginAccount.RoleKey)
|
||||
rc.ResData = map[string]interface{}{
|
||||
rc.ResData = map[string]any{
|
||||
"permissions": permis,
|
||||
"menus": Build(*menus),
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ func (p *NoticeApi) GetNoticeList(rc *ctx.ReqCtx) {
|
||||
notice := entity.SysNotice{NoticeType: noticeType, Title: title, DeptIds: ids}
|
||||
list, total := p.NoticeApp.FindListPage(pageNum, pageSize, notice)
|
||||
|
||||
rc.ResData = map[string]interface{}{
|
||||
rc.ResData = map[string]any{
|
||||
"data": list,
|
||||
"total": total,
|
||||
"pageNum": pageNum,
|
||||
|
||||
@@ -39,7 +39,7 @@ func (p *PostApi) GetPostList(rc *ctx.ReqCtx) {
|
||||
post := entity.SysPost{Status: status, PostName: postName, PostCode: postCode}
|
||||
list, total := p.PostApp.FindListPage(pageNum, pageSize, post)
|
||||
|
||||
rc.ResData = map[string]interface{}{
|
||||
rc.ResData = map[string]any{
|
||||
"data": list,
|
||||
"total": total,
|
||||
"pageNum": pageNum,
|
||||
|
||||
@@ -44,7 +44,7 @@ func (r *RoleApi) GetRoleList(rc *ctx.ReqCtx) {
|
||||
role := entity.SysRole{Status: status, RoleName: roleName, RoleKey: roleKey}
|
||||
list, total := r.RoleApp.FindListPage(pageNum, pageSize, role)
|
||||
|
||||
rc.ResData = map[string]interface{}{
|
||||
rc.ResData = map[string]any{
|
||||
"data": list,
|
||||
"total": total,
|
||||
"pageNum": pageNum,
|
||||
|
||||
@@ -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("没有权限")))
|
||||
}
|
||||
|
||||
// 登录账号信息
|
||||
|
||||
@@ -43,7 +43,7 @@ type UserApi struct {
|
||||
// @Router /system/user/getCaptcha [get]
|
||||
func (u *UserApi) GenerateCaptcha(c *gin.Context) {
|
||||
id, image := captcha.Generate()
|
||||
c.JSON(http.StatusOK, map[string]interface{}{"base64Captcha": image, "captchaId": id})
|
||||
c.JSON(http.StatusOK, map[string]any{"base64Captcha": image, "captchaId": id})
|
||||
}
|
||||
|
||||
// @Tags Base
|
||||
@@ -55,7 +55,7 @@ func (u *UserApi) RefreshToken(rc *ctx.ReqCtx) {
|
||||
tokenStr := rc.GinCtx.Request.Header.Get("X-TOKEN")
|
||||
token, err := ctx.RefreshToken(tokenStr)
|
||||
biz.ErrIsNil(err, "刷新token失败")
|
||||
rc.ResData = map[string]interface{}{"token": token, "expire": time.Now().Unix() + config.Conf.Jwt.ExpireTime}
|
||||
rc.ResData = map[string]any{"token": token, "expire": time.Now().Unix() + config.Conf.Jwt.ExpireTime}
|
||||
}
|
||||
|
||||
// @Tags Base
|
||||
@@ -89,7 +89,7 @@ func (u *UserApi) Login(rc *ctx.ReqCtx) {
|
||||
|
||||
biz.ErrIsNil(err, "生成Token失败")
|
||||
|
||||
rc.ResData = map[string]interface{}{
|
||||
rc.ResData = map[string]any{
|
||||
"token": token,
|
||||
"expire": time.Now().Unix() + config.Conf.Jwt.ExpireTime,
|
||||
}
|
||||
@@ -128,7 +128,7 @@ func (u *UserApi) Auth(rc *ctx.ReqCtx) {
|
||||
permis := u.RoleMenuApp.GetPermis(role.RoleId)
|
||||
menus := u.MenuApp.SelectMenuRole(role.RoleKey)
|
||||
|
||||
rc.ResData = map[string]interface{}{
|
||||
rc.ResData = map[string]any{
|
||||
"user": userData,
|
||||
"role": role,
|
||||
"permissions": permis,
|
||||
@@ -183,7 +183,7 @@ func (u *UserApi) GetSysUserList(rc *ctx.ReqCtx) {
|
||||
user.DeptId = int64(deptId)
|
||||
list, total := u.UserApp.FindListPage(pageNum, pageSize, user)
|
||||
|
||||
rc.ResData = map[string]interface{}{
|
||||
rc.ResData = map[string]any{
|
||||
"data": list,
|
||||
"total": total,
|
||||
"pageNum": pageNum,
|
||||
@@ -216,7 +216,7 @@ func (u *UserApi) GetSysUserProfile(rc *ctx.ReqCtx) {
|
||||
roleIds := make([]int64, 0)
|
||||
roleIds = append(roleIds, rc.LoginAccount.RoleId)
|
||||
|
||||
rc.ResData = map[string]interface{}{
|
||||
rc.ResData = map[string]any{
|
||||
"data": user,
|
||||
"postIds": postIds,
|
||||
"roleIds": roleIds,
|
||||
@@ -287,7 +287,7 @@ func (u *UserApi) GetSysUser(rc *ctx.ReqCtx) {
|
||||
|
||||
posts := u.PostApp.FindList(entity.SysPost{})
|
||||
|
||||
rc.ResData = map[string]interface{}{
|
||||
rc.ResData = map[string]any{
|
||||
"data": result,
|
||||
"postIds": result.PostIds,
|
||||
"roleIds": result.RoleIds,
|
||||
@@ -306,7 +306,7 @@ func (u *UserApi) GetSysUserInit(rc *ctx.ReqCtx) {
|
||||
roles := u.RoleApp.FindList(entity.SysRole{})
|
||||
|
||||
posts := u.PostApp.FindList(entity.SysPost{})
|
||||
mp := make(map[string]interface{}, 2)
|
||||
mp := make(map[string]any, 2)
|
||||
mp["roles"] = roles
|
||||
mp["posts"] = posts
|
||||
rc.ResData = mp
|
||||
@@ -334,7 +334,7 @@ func (u *UserApi) GetUserRolePost(rc *ctx.ReqCtx) {
|
||||
po := u.PostApp.FindOne(kgo.KConv.Str2Int64(postId))
|
||||
posts = append(posts, *po)
|
||||
}
|
||||
mp := make(map[string]interface{}, 2)
|
||||
mp := make(map[string]any, 2)
|
||||
mp["roles"] = roles
|
||||
mp["posts"] = posts
|
||||
rc.ResData = mp
|
||||
|
||||
Reference in New Issue
Block a user