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.

61 lines
1.6 KiB

  1. package service
  2. import (
  3. "gin-vue-admin/config"
  4. "gin-vue-admin/global"
  5. "gin-vue-admin/model"
  6. "gin-vue-admin/utils"
  7. "go.uber.org/zap"
  8. )
  9. // @title GetSystemConfig
  10. // @description 读取配置文件
  11. // @auth (2020/04/05 20:22)
  12. // @return err error
  13. // @return conf Server
  14. func GetSystemConfig() (err error, conf config.Server) {
  15. return nil, global.GVA_CONFIG
  16. }
  17. // @title SetSystemConfig
  18. // @description set system config, 设置配置文件
  19. // @auth (2020/04/05 20:22)
  20. // @param system model.System
  21. // @return err error
  22. func SetSystemConfig(system model.System) (err error) {
  23. cs := utils.StructToMap(system.Config)
  24. for k, v := range cs {
  25. global.GVA_VP.Set(k, v)
  26. }
  27. err = global.GVA_VP.WriteConfig()
  28. return err
  29. }
  30. // @title GetServerInfo
  31. // @description get server info , 获取服务器信息
  32. // @auth (2020/04/05 20:22)
  33. // @return server *utils.Server
  34. // @return err error
  35. func GetServerInfo() (server *utils.Server, err error) {
  36. var s utils.Server
  37. s.Os = utils.InitOS()
  38. if s.Cpu, err = utils.InitCPU(); err != nil{
  39. global.GVA_LOG.Error("func utils.InitCPU() Failed!", zap.String("err", err.Error()))
  40. return &s, err
  41. }
  42. if s.Rrm, err = utils.InitRAM(); err != nil{
  43. global.GVA_LOG.Error("func utils.InitRAM() Failed!", zap.String("err", err.Error()))
  44. return &s, err
  45. }
  46. if s.Disk, err = utils.InitDisk(); err != nil{
  47. global.GVA_LOG.Error("func utils.InitDisk() Failed!", zap.String("err", err.Error()))
  48. return &s, err
  49. }
  50. return &s, nil
  51. }