You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.5 KiB

  1. package v1
  2. import (
  3. "gin-vue-admin/global"
  4. "gin-vue-admin/model"
  5. "gin-vue-admin/model/response"
  6. "gin-vue-admin/service"
  7. "os"
  8. "os/exec"
  9. "runtime"
  10. "strconv"
  11. "github.com/gin-gonic/gin"
  12. "go.uber.org/zap"
  13. )
  14. // @Tags System
  15. // @Summary 获取配置文件内容
  16. // @Security ApiKeyAuth
  17. // @Produce application/json
  18. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  19. // @Router /system/getSystemConfig [post]
  20. func GetSystemConfig(c *gin.Context) {
  21. if err, config := service.GetSystemConfig(); err != nil {
  22. global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
  23. response.FailWithMessage("获取失败", c)
  24. } else {
  25. response.OkWithDetailed(response.SysConfigResponse{Config: config}, "获取成功", c)
  26. }
  27. }
  28. // @Tags System
  29. // @Summary 设置配置文件内容
  30. // @Security ApiKeyAuth
  31. // @Produce application/json
  32. // @Param data body model.System true "设置配置文件内容"
  33. // @Success 200 {string} string "{"success":true,"data":{},"msg":"设置成功"}"
  34. // @Router /system/setSystemConfig [post]
  35. func SetSystemConfig(c *gin.Context) {
  36. var sys model.System
  37. _ = c.ShouldBindJSON(&sys)
  38. if err := service.SetSystemConfig(sys); err != nil {
  39. global.GVA_LOG.Error("设置失败!", zap.Any("err", err))
  40. response.FailWithMessage("设置失败", c)
  41. } else {
  42. response.OkWithData("设置成功", c)
  43. }
  44. }
  45. // @Tags System
  46. // @Summary 重启系统
  47. // @Security ApiKeyAuth
  48. // @Produce application/json
  49. // @Success 200 {string} string "{"code":0,"data":{},"msg":"重启系统成功"}"
  50. // @Router /system/reloadSystem [post]
  51. func ReloadSystem(c *gin.Context) {
  52. if runtime.GOOS == "windows" {
  53. response.FailWithMessage("系统不支持", c)
  54. return
  55. }
  56. pid := os.Getpid()
  57. cmd := exec.Command("kill", "-1", strconv.Itoa(pid))
  58. err := cmd.Run()
  59. if err != nil {
  60. global.GVA_LOG.Error("重启系统失败!", zap.Any("err", err))
  61. response.FailWithMessage("重启系统失败", c)
  62. return
  63. }
  64. response.OkWithMessage("重启系统成功", c)
  65. return
  66. }
  67. // @Tags System
  68. // @Summary 获取服务器信息
  69. // @Security ApiKeyAuth
  70. // @Produce application/json
  71. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  72. // @Router /system/getServerInfo [post]
  73. func GetServerInfo(c *gin.Context) {
  74. if server, err := service.GetServerInfo(); err != nil {
  75. global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
  76. response.FailWithMessage("获取失败", c)
  77. return
  78. } else {
  79. response.OkWithDetailed(gin.H{"server": server}, "获取成功", c)
  80. }
  81. }