feat: add .env file existence check before loading environment variables
This commit is contained in:
parent
5fb0764630
commit
84239864c1
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"legalgo-BE-go/config"
|
||||
"legalgo-BE-go/database"
|
||||
@ -12,8 +13,14 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := godotenv.Load(); err != nil {
|
||||
log.Fatal("cannot load environment file")
|
||||
// Check if the .env file exists
|
||||
if _, err := os.Stat(".env"); err == nil {
|
||||
// Load environment variables from .env file if it exists
|
||||
if err := godotenv.Load(); err != nil {
|
||||
log.Println("Error loading .env file, continuing without it")
|
||||
}
|
||||
} else {
|
||||
log.Println(".env file not found, skipping load")
|
||||
}
|
||||
|
||||
config.InitEnv()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user