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.

60 lines
1.8 KiB

3 years ago
  1. package system
  2. import (
  3. "github.com/flipped-aurora/gin-vue-admin/server/config"
  4. "github.com/flipped-aurora/gin-vue-admin/server/global"
  5. "github.com/flipped-aurora/gin-vue-admin/server/model/system"
  6. "github.com/flipped-aurora/gin-vue-admin/server/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. func (systemConfigService *SystemConfigService) GetSystemConfig() (err error, conf config.Server) {
  15. return nil, global.GVA_CONFIG
  16. }
  17. // @description set system config,
  18. //@author: [piexlmax](https://github.com/piexlmax)
  19. //@function: SetSystemConfig
  20. //@description: 设置配置文件
  21. //@param: system model.System
  22. //@return: err error
  23. func (systemConfigService *SystemConfigService) SetSystemConfig(system system.System) (err error) {
  24. cs := utils.StructToMap(system.Config)
  25. for k, v := range cs {
  26. global.GVA_VP.Set(k, v)
  27. }
  28. err = global.GVA_VP.WriteConfig()
  29. return err
  30. }
  31. //@author: [SliverHorn](https://github.com/SliverHorn)
  32. //@function: GetServerInfo
  33. //@description: 获取服务器信息
  34. //@return: server *utils.Server, err error
  35. func (systemConfigService *SystemConfigService) 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. }