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.

89 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. // @Param data body model.System true "重启系统"
  50. // @Success 200 {string} string "{"success":true,"data":{},"msg":"重启系统成功"}"
  51. // @Router /system/ReloadSystem [post]
  52. func ReloadSystem(c *gin.Context) {
  53. if runtime.GOOS == "windows" {
  54. response.FailWithMessage("系统不支持", c)
  55. return
  56. }
  57. pid := os.Getpid()
  58. cmd := exec.Command("kill", "-1", strconv.Itoa(pid))
  59. err := cmd.Run()
  60. if err != nil {
  61. global.GVA_LOG.Error("重启系统失败!", zap.Any("err", err))
  62. response.FailWithMessage("重启系统失败", c)
  63. return
  64. }
  65. response.OkWithMessage("重启系统成功", c)
  66. return
  67. }
  68. // @Tags System
  69. // @Summary 获取服务器信息
  70. // @Security ApiKeyAuth
  71. // @Produce application/json
  72. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  73. // @Router /system/getServerInfo [post]
  74. func GetServerInfo(c *gin.Context) {
  75. if server, err := service.GetServerInfo(); err != nil {
  76. global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
  77. response.FailWithMessage("获取失败", c)
  78. return
  79. } else {
  80. response.OkWithDetailed(gin.H{"server": server}, "获取成功", c)
  81. }
  82. }