specify the base directory for loading the .env file
This commit is contained in:
parent
4836162f40
commit
3ee15497a5
@ -3,24 +3,26 @@ package initializers
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func LoadEnvVariables() {
|
func LoadEnvVariables(baseDir string) {
|
||||||
err := godotenv.Load()
|
envDir := path.Join(baseDir, ".env")
|
||||||
|
err := godotenv.Load(envDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error loading .env file")
|
log.Fatal("Error loading .env file", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper to get environment variables with a default fallback
|
// Helper to get environment variables with a default fallback
|
||||||
func GetEnv(key, defaultVal string) string {
|
func GetEnv(key, defaultVal string) string {
|
||||||
if value, exists := os.LookupEnv(key); exists {
|
if value, exists := os.LookupEnv(key); exists {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
return defaultVal
|
return defaultVal
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper to safely convert environment variables to uint
|
// Helper to safely convert environment variables to uint
|
||||||
|
Loading…
Reference in New Issue
Block a user