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.

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