From aaa155ca2f4635597562881cdc3f92ca2c4133ab Mon Sep 17 00:00:00 2001 From: stuzer05 Date: Mon, 7 Oct 2024 12:26:44 +0300 Subject: [PATCH] Load .env from executable path --- main.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 2f3c41f..43101ae 100644 --- a/main.go +++ b/main.go @@ -5,12 +5,21 @@ import ( "gitea.stuzer.link/stuzer05/docker-registry-manager/cmd" "gitea.stuzer.link/stuzer05/docker-registry-manager/internal/app" "github.com/joho/godotenv" + "log" "os" + "path/filepath" ) func main() { + // Get executable directory + exePath, err := os.Executable() + if err != nil { + log.Fatal("Error getting executable path:", err) + } + exeDir := filepath.Dir(exePath) + // Load .env file - err := godotenv.Load() + err = godotenv.Load(filepath.Join(exeDir, ".env")) if err != nil { fmt.Println("Error loading .env file:", err) return