zhangqian
2024-04-19 cdb38521ea1f662b53bafb87412c38dfd0d5e11d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package system
 
import (
    "srm/global"
    "srm/model/common/response"
    "srm/model/system"
    "srm/utils"
 
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
)
 
type SystemApi struct{}
 
// GetSystemConfig
// @Tags      System
// @Summary   获取配置文件内容
// @Security  ApiKeyAuth
// @Produce   application/json
// @Success   200  {object}  response.Response{data=system.System,msg=string}  "获取配置文件内容,返回包括系统配置"
// @Router    /system/getSystemConfig [post]
func (s *SystemApi) GetSystemConfig(c *gin.Context) {
    config, err := systemConfigService.GetSystemConfig()
    if err != nil {
        global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败", c)
        return
    }
    response.OkWithDetailed(system.System{Config: config}, "获取成功", c)
}
 
// SetSystemConfig
// @Tags      System
// @Summary   设置配置文件内容
// @Security  ApiKeyAuth
// @Produce   application/json
// @Param     data  body      system.System                   true  "设置配置文件内容"
// @Success   200   {object}  response.Response{data=string}  "设置配置文件内容"
// @Router    /system/setSystemConfig [post]
func (s *SystemApi) SetSystemConfig(c *gin.Context) {
    var sys system.System
    err := c.ShouldBindJSON(&sys)
    if err != nil {
        response.FailWithMessage(err.Error(), c)
        return
    }
    err = systemConfigService.SetSystemConfig(sys)
    if err != nil {
        global.GVA_LOG.Error("设置失败!", zap.Error(err))
        response.FailWithMessage("设置失败", c)
        return
    }
    response.OkWithMessage("设置成功", c)
}
 
// ReloadSystem
// @Tags      System
// @Summary   重启系统
// @Security  ApiKeyAuth
// @Produce   application/json
// @Success   200  {object}  response.Response{msg=string}  "重启系统"
// @Router    /system/reloadSystem [post]
func (s *SystemApi) ReloadSystem(c *gin.Context) {
    err := utils.Reload()
    if err != nil {
        global.GVA_LOG.Error("重启系统失败!", zap.Error(err))
        response.FailWithMessage("重启系统失败", c)
        return
    }
    response.OkWithMessage("重启系统成功", c)
}
 
// GetServerInfo
// @Tags      System
// @Summary   获取服务器信息
// @Security  ApiKeyAuth
// @Produce   application/json
// @Success   200  {object}  response.Response{data=map[string]interface{},msg=string}  "获取服务器信息"
// @Router    /system/getServerInfo [post]
func (s *SystemApi) GetServerInfo(c *gin.Context) {
    server, err := systemConfigService.GetServerInfo()
    if err != nil {
        global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败", c)
        return
    }
    response.OkWithDetailed(gin.H{"server": server}, "获取成功", c)
}