Load .env from executable path

This commit is contained in:
Illya Marchenko 2024-10-07 12:26:44 +03:00
parent f690d5c54f
commit aaa155ca2f
Signed by: stuzer05
GPG Key ID: A6ABAAA9268F9F4F

11
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