forked from nixcn/nixcn-cms
Add dev services
- Development dotenvs - Caddy service - Redis service - Postgres service - Fix env parser error Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
@@ -9,32 +9,33 @@ import (
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
func GetEnv(Key string) string {
|
||||
func GetEnv(key string) string {
|
||||
_ = godotenv.Load()
|
||||
return os.Getenv(Key)
|
||||
upperKey := strings.ToUpper(key)
|
||||
return os.Getenv(upperKey)
|
||||
}
|
||||
|
||||
func SetEnvConf(ConfKey string, ConfSub string) {
|
||||
var Config = []string{ConfKey, ConfSub}
|
||||
var EnvKey = strings.Join(Config, "_")
|
||||
env := GetEnv(EnvKey)
|
||||
var orig = Get(ConfKey + "." + ConfSub)
|
||||
func SetEnvConf(key string, sub string) {
|
||||
envJoin := strings.Join([]string{key, sub}, "_")
|
||||
env := GetEnv(envJoin)
|
||||
confJoin := strings.Join([]string{key, sub}, ".")
|
||||
orig := Get(confJoin)
|
||||
if env != "" {
|
||||
switch orig.(type) {
|
||||
case string:
|
||||
Set(ConfKey, env)
|
||||
Set(confJoin, env)
|
||||
case int:
|
||||
conv, err := strconv.Atoi(env)
|
||||
if err != nil {
|
||||
log.Panic("[Config] Error converting string to int: ", err)
|
||||
}
|
||||
Set(ConfKey, conv)
|
||||
Set(confJoin, conv)
|
||||
case bool:
|
||||
switch env {
|
||||
case "true":
|
||||
Set(ConfKey, true)
|
||||
Set(confJoin, true)
|
||||
case "false":
|
||||
Set(ConfKey, false)
|
||||
Set(confJoin, false)
|
||||
}
|
||||
case []string:
|
||||
trim := strings.TrimSpace(env)
|
||||
@@ -46,7 +47,7 @@ func SetEnvConf(ConfKey string, ConfSub string) {
|
||||
trimSub = strings.TrimSuffix(trimSub, "\"")
|
||||
envArray = append(envArray, trimSub)
|
||||
}
|
||||
Set(ConfKey, envArray)
|
||||
Set(confJoin, envArray)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user