From 4ec50cee8a6d1c65483710a2e559056fe2d3bb9e Mon Sep 17 00:00:00 2001 From: Ardeman Date: Thu, 27 Feb 2025 22:32:38 +0800 Subject: [PATCH] feat: add check for .env file existence before loading environment variables --- cmd/legalgo/main.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cmd/legalgo/main.go b/cmd/legalgo/main.go index af22862..9c2a8e9 100644 --- a/cmd/legalgo/main.go +++ b/cmd/legalgo/main.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "log" + "os" "legalgo-BE-go/config" "legalgo-BE-go/database" @@ -18,8 +19,14 @@ import ( ) func init() { - 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()