sys_system.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. }
  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. }