✨ init project
This commit is contained in:
62
service/system/sys_system.go
Normal file
62
service/system/sys_system.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"git.echol.cn/loser/lckt/config"
|
||||
"git.echol.cn/loser/lckt/global"
|
||||
"git.echol.cn/loser/lckt/model/system"
|
||||
"git.echol.cn/loser/lckt/utils"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
//@author: [piexlmax](https://github.com/piexlmax)
|
||||
//@function: GetSystemConfig
|
||||
//@description: 读取配置文件
|
||||
//@return: conf config.Server, err error
|
||||
|
||||
type SystemConfigService struct{}
|
||||
|
||||
var SystemConfigServiceApp = new(SystemConfigService)
|
||||
|
||||
func (systemConfigService *SystemConfigService) GetSystemConfig() (conf config.Server, err error) {
|
||||
return global.GVA_CONFIG, nil
|
||||
}
|
||||
|
||||
// @description set system config,
|
||||
//@author: [piexlmax](https://github.com/piexlmax)
|
||||
//@function: SetSystemConfig
|
||||
//@description: 设置配置文件
|
||||
//@param: system model.System
|
||||
//@return: err error
|
||||
|
||||
func (systemConfigService *SystemConfigService) SetSystemConfig(system system.System) (err error) {
|
||||
cs := utils.StructToMap(system.Config)
|
||||
for k, v := range cs {
|
||||
global.GVA_VP.Set(k, v)
|
||||
}
|
||||
err = global.GVA_VP.WriteConfig()
|
||||
return err
|
||||
}
|
||||
|
||||
//@author: [SliverHorn](https://github.com/SliverHorn)
|
||||
//@function: GetServerInfo
|
||||
//@description: 获取服务器信息
|
||||
//@return: server *utils.Server, err error
|
||||
|
||||
func (systemConfigService *SystemConfigService) GetServerInfo() (server *utils.Server, err error) {
|
||||
var s utils.Server
|
||||
s.Os = utils.InitOS()
|
||||
if s.Cpu, err = utils.InitCPU(); err != nil {
|
||||
global.GVA_LOG.Error("func utils.InitCPU() Failed", zap.String("err", err.Error()))
|
||||
return &s, err
|
||||
}
|
||||
if s.Ram, err = utils.InitRAM(); err != nil {
|
||||
global.GVA_LOG.Error("func utils.InitRAM() Failed", zap.String("err", err.Error()))
|
||||
return &s, err
|
||||
}
|
||||
if s.Disk, err = utils.InitDisk(); err != nil {
|
||||
global.GVA_LOG.Error("func utils.InitDisk() Failed", zap.String("err", err.Error()))
|
||||
return &s, err
|
||||
}
|
||||
|
||||
return &s, nil
|
||||
}
|
||||
Reference in New Issue
Block a user