43 lines
947 B
Go
43 lines
947 B
Go
package env
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
|
|
"git.apinb.com/bsm-sdk/engine/types"
|
|
)
|
|
|
|
var MeshEnv *types.MeshEnv = nil
|
|
|
|
// get system env.
|
|
func NewEnv() *types.MeshEnv {
|
|
if MeshEnv == nil {
|
|
MeshEnv = &types.MeshEnv{
|
|
Workspace: GetEnvDefault("BlocksMesh_Workspace", "bsm"),
|
|
Prefix: GetEnvDefault("BlocksMesh_Prefix", "/usr/local/bsm"),
|
|
JwtSecretKey: GetEnvDefault("BlocksMesh_JwtSecretKey", "Cblocksmesh2022C"),
|
|
RuntimeMode: strings.ToLower(GetEnvDefault("BlocksMesh_RuntimeMode", "dev")),
|
|
}
|
|
}
|
|
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
|
|
}
|