dev
This commit is contained in:
parent
6a939f7082
commit
76a4b67269
|
@ -1,5 +1,7 @@
|
||||||
# core
|
# 私有仓库:core 设置
|
||||||
|
```
|
||||||
go env -w GOPRIVATE=git.apinb.com/*
|
go env -w GOPRIVATE=git.apinb.com/*
|
||||||
go env -w GONOPROXY=git.apinb.com/*
|
go env -w GONOPROXY=git.apinb.com/*
|
||||||
go env -w GOINSECURE=git.apinb.com/*
|
go env -w GOINSECURE=git.apinb.com/*
|
||||||
go env -w GONOSUMDB=git.apinb.com/*
|
go env -w GONOSUMDB=git.apinb.com/*
|
||||||
|
```
|
||||||
|
|
21
conf/new.go
21
conf/new.go
|
@ -8,10 +8,11 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"math/rand/v2"
|
||||||
|
|
||||||
"git.apinb.com/bsm-sdk/core/env"
|
"git.apinb.com/bsm-sdk/core/env"
|
||||||
"git.apinb.com/bsm-sdk/core/print"
|
"git.apinb.com/bsm-sdk/core/print"
|
||||||
"git.apinb.com/bsm-sdk/core/vars"
|
"git.apinb.com/bsm-sdk/core/vars"
|
||||||
"golang.org/x/exp/rand"
|
|
||||||
yaml "gopkg.in/yaml.v3"
|
yaml "gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -24,32 +25,32 @@ func New(srvKey string, cfg any) *Runtime {
|
||||||
vars.HostName, _ = os.Hostname()
|
vars.HostName, _ = os.Hostname()
|
||||||
|
|
||||||
// 获取根目录路径,优先使用环境变量设置的路径,如果未设置则使用当前工作目录
|
// 获取根目录路径,优先使用环境变量设置的路径,如果未设置则使用当前工作目录
|
||||||
rootDir := strings.ToLower(env.GetEnvDefault("CORE_Path", ""))
|
rootDir := strings.ToLower(env.GetEnvDefault("BSM_Path", ""))
|
||||||
if rootDir == "" {
|
if rootDir == "" {
|
||||||
rootDir, _ = os.Getwd()
|
rootDir, _ = os.Getwd()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取运行模式,如果环境变量未设置,则默认为"dev"
|
// 获取运行模式,如果环境变量未设置,则默认为"dev"
|
||||||
run.Mode = strings.ToLower(env.GetEnvDefault("CORE_Mode", "dev"))
|
run.Mode = strings.ToLower(env.GetEnvDefault("BSM_Mode", "dev"))
|
||||||
|
|
||||||
// 获取JWT密钥,用于身份验证
|
// 获取JWT密钥,用于身份验证
|
||||||
run.JwtKey = strings.ToLower(env.GetEnvDefault("CORE_JwtKey", ""))
|
run.JwtKey = strings.ToLower(env.GetEnvDefault("BSM_JwtKey", ""))
|
||||||
|
|
||||||
// 获取许可证路径,如果环境变量未设置,则默认在根目录下的"etc"文件夹
|
// 获取许可证路径,如果环境变量未设置,则默认在根目录下的"etc"文件夹
|
||||||
run.LicencePath = strings.ToLower(env.GetEnvDefault("CORE_LicencePath", ""))
|
run.LicencePath = strings.ToLower(env.GetEnvDefault("BSM_LicencePath", ""))
|
||||||
if run.LicencePath == "" {
|
if run.LicencePath == "" {
|
||||||
run.LicencePath = filepath.Join(rootDir, "etc")
|
run.LicencePath = filepath.Join(rootDir, "etc")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果JWT密钥未设置,则记录错误并终止程序
|
// 如果JWT密钥未设置,则记录错误并终止程序
|
||||||
if run.JwtKey == "" {
|
if run.JwtKey == "" {
|
||||||
log.Fatalf("ENV: CORE_JwtKey Not Nil !")
|
log.Fatalf("ENV: BSM_JwtKey Not Nil !")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构造配置文件路径,输出配置文件信息
|
// 构造配置文件路径,输出配置文件信息
|
||||||
cfp := fmt.Sprintf("%s_%s.yaml", srvKey, run.Mode)
|
cfp := fmt.Sprintf("%s_%s.yaml", srvKey, run.Mode)
|
||||||
cfp = filepath.Join(rootDir, "etc", cfp)
|
cfp = filepath.Join(rootDir, "etc", cfp)
|
||||||
print.Info("[CORE - %s] Config File: %s", srvKey, cfp)
|
print.Info("[BSM - %s] Config File: %s", srvKey, cfp)
|
||||||
|
|
||||||
// 读取配置文件内容
|
// 读取配置文件内容
|
||||||
yamlFile, err := os.ReadFile(cfp)
|
yamlFile, err := os.ReadFile(cfp)
|
||||||
|
@ -57,7 +58,7 @@ func New(srvKey string, cfg any) *Runtime {
|
||||||
log.Fatalf("ERROR: %v", err)
|
log.Fatalf("ERROR: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查配置文件中是否存在Service和Addr字段
|
// 检查配置文件中是否存在Service和Port字段
|
||||||
if !strings.Contains(string(yamlFile), "Service:") {
|
if !strings.Contains(string(yamlFile), "Service:") {
|
||||||
log.Fatalln("ERROR: Service Not Nil", cfp)
|
log.Fatalln("ERROR: Service Not Nil", cfp)
|
||||||
}
|
}
|
||||||
|
@ -85,8 +86,8 @@ func NotNil(values ...string) {
|
||||||
|
|
||||||
func CheckPort(port int) int {
|
func CheckPort(port int) int {
|
||||||
if port <= 0 || port >= 65535 {
|
if port <= 0 || port >= 65535 {
|
||||||
rand.Seed(uint64(time.Now().UnixNano()))
|
r := rand.New(rand.NewPCG(1000, uint64(time.Now().UnixNano())))
|
||||||
return rand.Intn(65535-1024) + 1024 // 生成1024到65535之间的随机端口
|
return r.IntN(65535-1024) + 1024 // 生成1024到65535之间的随机端口
|
||||||
}
|
}
|
||||||
return port
|
return port
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue