From 7c1e74b3a873e7ee22d5f3e26d1230ba0bc00787 Mon Sep 17 00:00:00 2001 From: c9s Date: Wed, 17 Feb 2021 17:28:31 +0800 Subject: [PATCH] switch current working dir to the resource dir of the executable --- cmd/bbgo-desktop/main.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cmd/bbgo-desktop/main.go b/cmd/bbgo-desktop/main.go index 97863b071..09b2933ed 100644 --- a/cmd/bbgo-desktop/main.go +++ b/cmd/bbgo-desktop/main.go @@ -5,6 +5,7 @@ import ( "net" "os" "os/signal" + "path/filepath" "runtime" "github.com/joho/godotenv" @@ -18,8 +19,18 @@ import ( ) func main() { - dotenvFile := ".env.local" + ep, err := os.Executable() + if err != nil { + log.Fatalln("failed to find the current executable:", err) + } + err = os.Chdir(filepath.Join(filepath.Dir(ep), "..", "Resources")) + if err != nil { + log.Fatalln("chdir error:", err) + } + + + dotenvFile := ".env.local" if _, err := os.Stat(dotenvFile) ; err == nil { if err := godotenv.Load(dotenvFile); err != nil { log.WithError(err).Error("error loading dotenv file")