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:
2025-12-20 01:27:11 +08:00
parent 0fb5c8b758
commit f130401ff8
8 changed files with 88 additions and 17 deletions

View File

@@ -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)
}
}
}