mirror of
https://github.com/LeRoid-hub/Bookholder-API.git
synced 2025-01-31 02:34:57 +00:00
Config checks if DB vars are set
This commit is contained in:
parent
b0339d13b2
commit
bf5dfb06b0
@ -3,7 +3,6 @@ package config
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
)
|
)
|
||||||
@ -38,8 +37,26 @@ func Load() map[string]string {
|
|||||||
fmt.Println("no environment variables are set")
|
fmt.Println("no environment variables are set")
|
||||||
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user