This commit is contained in:
2025-02-07 20:33:27 +08:00
parent 76a4b67269
commit e89e1a372a
28 changed files with 276 additions and 1691 deletions

View File

@@ -16,40 +16,18 @@ import (
yaml "gopkg.in/yaml.v3"
)
func New(srvKey string, cfg any) *Runtime {
var run Runtime
func New(srvKey string, cfg any) {
env.NewEnv()
// 设置服务键
vars.ServiceKey = srvKey
// 获取主机名
vars.HostName, _ = os.Hostname()
// 获取根目录路径,优先使用环境变量设置的路径,如果未设置则使用当前工作目录
rootDir := strings.ToLower(env.GetEnvDefault("BSM_Path", ""))
if rootDir == "" {
rootDir, _ = os.Getwd()
}
// 获取运行模式,如果环境变量未设置,则默认为"dev"
run.Mode = strings.ToLower(env.GetEnvDefault("BSM_Mode", "dev"))
// 获取JWT密钥用于身份验证
run.JwtKey = strings.ToLower(env.GetEnvDefault("BSM_JwtKey", ""))
// 获取许可证路径,如果环境变量未设置,则默认在根目录下的"etc"文件夹
run.LicencePath = strings.ToLower(env.GetEnvDefault("BSM_LicencePath", ""))
if run.LicencePath == "" {
run.LicencePath = filepath.Join(rootDir, "etc")
}
// 如果JWT密钥未设置则记录错误并终止程序
if run.JwtKey == "" {
log.Fatalf("ENV: BSM_JwtKey Not Nil !")
}
// 构造配置文件路径,输出配置文件信息
cfp := fmt.Sprintf("%s_%s.yaml", srvKey, run.Mode)
cfp = filepath.Join(rootDir, "etc", cfp)
cfp := fmt.Sprintf("%s_%s.yaml", srvKey, env.Runtime.Mode)
cfp = filepath.Join(env.Runtime.Prefix, "etc", cfp)
print.Info("[BSM - %s] Config File: %s", srvKey, cfp)
// 读取配置文件内容
@@ -72,8 +50,6 @@ func New(srvKey string, cfg any) *Runtime {
if err != nil {
log.Fatalf("ERROR: %v", err)
}
return &run
}
func NotNil(values ...string) {

View File

@@ -49,12 +49,6 @@ type MqConf struct {
Space string `yaml:"Space"` // MQ服务空间
}
type Runtime struct {
Mode string // 运行模式dev,test,prod
JwtKey string // JWT密钥
LicencePath string // Licence文件路径
}
type TlsConf struct {
CaFile string // CA文件路径
CertFile string // 证书文件路径