Files
mayfly-go/server/internal/machine/config/config.go

58 lines
1.7 KiB
Go
Raw Normal View History

package config
import (
sysapp "mayfly-go/internal/sys/application"
"mayfly-go/pkg/logx"
"mayfly-go/pkg/utils/bytex"
2024-03-21 17:15:52 +08:00
"github.com/may-fly/cast"
)
const (
ConfigKeyMachine string = "MachineConfig" // 机器相关配置
)
type Machine struct {
TerminalRecPath string // 终端操作记录存储位置
UploadMaxFileSize int64 // 允许上传的最大文件size
TermOpSaveDays int // 终端记录保存天数
GuacdHost string // guacd服务地址 默认 127.0.0.1
GuacdPort int // guacd服务端口 默认 4822
GuacdFilePath string // guacd服务文件存储位置用于挂载RDP文件夹
GuacdRecPath string // guacd服务记录存储位置用于记录rdp操作记录
}
// 获取机器相关配置
func GetMachine() *Machine {
c := sysapp.GetConfigApp().GetConfig(ConfigKeyMachine)
jm := c.GetJsonMap()
mc := new(Machine)
terminalRecPath := jm["terminalRecPath"]
if terminalRecPath == "" {
terminalRecPath = "./rec"
}
mc.TerminalRecPath = terminalRecPath
// 将1GB等字符串转为int64的byte
uploadMaxFileSizeStr := jm["uploadMaxFileSize"]
var uploadMaxFileSize int64 = 1 * bytex.GB
if uploadMaxFileSizeStr != "" {
var err error
uploadMaxFileSize, err = bytex.ParseSize(uploadMaxFileSizeStr)
if err != nil {
logx.Errorf("解析机器配置的最大上传文件大小失败: uploadMaxFileSize=%s, 使用系统默认值1GB", uploadMaxFileSizeStr)
}
}
mc.UploadMaxFileSize = uploadMaxFileSize
2024-03-21 17:15:52 +08:00
mc.TermOpSaveDays = cast.ToIntD(jm["termOpSaveDays"], 30)
// guacd
2024-04-06 18:19:17 +08:00
mc.GuacdHost = cast.ToString(jm["guacdHost"])
mc.GuacdPort = cast.ToIntD(jm["guacdPort"], 4822)
mc.GuacdFilePath = cast.ToStringD(jm["guacdFilePath"], "")
mc.GuacdRecPath = cast.ToStringD(jm["guacdRecPath"], "")
return mc
}