switch current working dir to the resource dir of the executable

This commit is contained in:
c9s 2021-02-17 17:28:31 +08:00
parent ea27a291db
commit 7c1e74b3a8

View File

@ -5,6 +5,7 @@ import (
"net" "net"
"os" "os"
"os/signal" "os/signal"
"path/filepath"
"runtime" "runtime"
"github.com/joho/godotenv" "github.com/joho/godotenv"
@ -18,8 +19,18 @@ import (
) )
func main() { 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 := os.Stat(dotenvFile) ; err == nil {
if err := godotenv.Load(dotenvFile); err != nil { if err := godotenv.Load(dotenvFile); err != nil {
log.WithError(err).Error("error loading dotenv file") log.WithError(err).Error("error loading dotenv file")