engine/env/env.go

54 lines
1.2 KiB
Go
Raw Normal View History

2024-02-11 01:31:01 +08:00
package env
import (
"os"
"strings"
"git.apinb.com/bsm-sdk/engine/types"
2024-09-29 11:58:44 +08:00
"git.apinb.com/bsm-sdk/engine/utils"
2024-02-11 01:31:01 +08:00
)
var MeshEnv *types.MeshEnv = nil
// get system env.
func NewEnv() *types.MeshEnv {
if MeshEnv == nil {
MeshEnv = &types.MeshEnv{
2024-12-03 18:53:11 +08:00
Workspace: GetEnvDefault("BlocksMesh_Workspace", "def"),
2024-02-11 01:31:01 +08:00
JwtSecretKey: GetEnvDefault("BlocksMesh_JwtSecretKey", "Cblocksmesh2022C"),
RuntimeMode: strings.ToLower(GetEnvDefault("BlocksMesh_RuntimeMode", "dev")),
}
2024-09-29 11:58:44 +08:00
if MeshEnv.RuntimeMode == "dev" {
MeshEnv.Prefix = GetEnvDefault("BlocksMesh_Prefix", utils.GetCurrentPath())
} else {
MeshEnv.Prefix = GetEnvDefault("BlocksMesh_Prefix", "/usr/local/bsm")
}
2024-02-11 01:31:01 +08:00
}
return MeshEnv
}
2024-09-17 18:54:13 +08:00
// get system base env.
func NewBaseEnv() *types.MeshEnv {
if MeshEnv == nil {
MeshEnv = &types.MeshEnv{
RuntimeMode: strings.ToLower(GetEnvDefault("BlocksMesh_RuntimeMode", "dev")),
}
2024-10-03 20:39:18 +08:00
if MeshEnv.RuntimeMode == "dev" {
MeshEnv.Prefix = GetEnvDefault("BlocksMesh_Prefix", utils.GetCurrentPath())
} else {
MeshEnv.Prefix = GetEnvDefault("BlocksMesh_Prefix", "/usr/local/bsm")
}
2024-09-17 18:54:13 +08:00
}
return MeshEnv
}
2024-02-11 01:31:01 +08:00
func GetEnvDefault(key string, def string) string {
value := os.Getenv(key)
if value == "" {
return def
}
return value
}