Load .env from executable path
This commit is contained in:
parent
f690d5c54f
commit
aaa155ca2f
11
main.go
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user