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.

59 lines
1.5 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. //@author: [piexlmax](https://github.com/piexlmax)
  10. //@function: GetSystemConfig
  11. //@description: 读取配置文件
  12. //@return: err error, conf config.Server
  13. func GetSystemConfig() (err error, conf config.Server) {
  14. return nil, global.GVA_CONFIG
  15. }
  16. // @description set system config,
  17. //@author: [piexlmax](https://github.com/piexlmax)
  18. //@function: SetSystemConfig
  19. //@description: 设置配置文件
  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. //@author: [SliverHorn](https://github.com/SliverHorn)
  31. //@function: GetServerInfo
  32. //@description: 获取服务器信息
  33. //@return: server *utils.Server, err error
  34. func GetServerInfo() (server *utils.Server, err error) {
  35. var s utils.Server
  36. s.Os = utils.InitOS()
  37. if s.Cpu, err = utils.InitCPU(); err != nil{
  38. global.GVA_LOG.Error("func utils.InitCPU() Failed!", zap.String("err", err.Error()))
  39. return &s, err
  40. }
  41. if s.Rrm, err = utils.InitRAM(); err != nil{
  42. global.GVA_LOG.Error("func utils.InitRAM() Failed!", zap.String("err", err.Error()))
  43. return &s, err
  44. }
  45. if s.Disk, err = utils.InitDisk(); err != nil{
  46. global.GVA_LOG.Error("func utils.InitDisk() Failed!", zap.String("err", err.Error()))
  47. return &s, err
  48. }
  49. return &s, nil
  50. }