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.7 KiB

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