Config checks if DB vars are set

This commit is contained in:
Jan 2024-12-14 15:51:29 +01:00
parent b0339d13b2
commit bf5dfb06b0

View File

@ -3,7 +3,6 @@ package config
import ( import (
"fmt" "fmt"
"os" "os"
"strings"
"github.com/joho/godotenv" "github.com/joho/godotenv"
) )
@ -39,7 +38,25 @@ func Load() map[string]string {
os.Exit(1) os.Exit(1)
} }
// TODO: check if all the required environment variables are set checkDB(env)
return env return env
} }
func checkDB(env map[string]string) {
required := []string{"DB_USER", "DB_PASSWORD", "DB_NAME", "DB_HOST", "DB_PORT"}
for _, item := range required {
checkEnv(item, env)
}
}
func checkEnv(check string, env map[string]string) {
if val, ok := env[check]; ok {
if val == "" {
fmt.Println(check, "is not set")
os.Exit(1)
}
} else {
fmt.Println(check, "is not set")
os.Exit(1)
}
}