49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package env
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
|
|
"git.apinb.com/bsm-sdk/engine/types"
|
|
"git.apinb.com/bsm-sdk/engine/utils"
|
|
)
|
|
|
|
var MeshEnv *types.MeshEnv = nil
|
|
|
|
// get system env.
|
|
func NewEnv() *types.MeshEnv {
|
|
if MeshEnv == nil {
|
|
MeshEnv = &types.MeshEnv{
|
|
Workspace: GetEnvDefault("BlocksMesh_Workspace", "bsm"),
|
|
JwtSecretKey: GetEnvDefault("BlocksMesh_JwtSecretKey", "Cblocksmesh2022C"),
|
|
RuntimeMode: strings.ToLower(GetEnvDefault("BlocksMesh_RuntimeMode", "dev")),
|
|
}
|
|
|
|
if MeshEnv.RuntimeMode == "dev" {
|
|
MeshEnv.Prefix = GetEnvDefault("BlocksMesh_Prefix", utils.GetCurrentPath())
|
|
} else {
|
|
MeshEnv.Prefix = GetEnvDefault("BlocksMesh_Prefix", "/usr/local/bsm")
|
|
}
|
|
}
|
|
return MeshEnv
|
|
}
|
|
|
|
// get system base env.
|
|
func NewBaseEnv() *types.MeshEnv {
|
|
if MeshEnv == nil {
|
|
MeshEnv = &types.MeshEnv{
|
|
Prefix: GetEnvDefault("BlocksMesh_Prefix", "/usr/local/bsm"),
|
|
RuntimeMode: strings.ToLower(GetEnvDefault("BlocksMesh_RuntimeMode", "dev")),
|
|
}
|
|
}
|
|
return MeshEnv
|
|
}
|
|
|
|
func GetEnvDefault(key string, def string) string {
|
|
value := os.Getenv(key)
|
|
if value == "" {
|
|
return def
|
|
}
|
|
return value
|
|
}
|