From 6b2714a5c5a6dcebe0916241e5175b4735370be0 Mon Sep 17 00:00:00 2001 From: 13715390423 <13715390423@163.com> Date: Tue, 30 Apr 2019 15:51:02 +0800 Subject: [PATCH] commit --- osmanthuswine.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/osmanthuswine.go b/osmanthuswine.go index be84b4c..690a709 100644 --- a/osmanthuswine.go +++ b/osmanthuswine.go @@ -24,6 +24,12 @@ import ( var chiRouter *chi.Mux +func init() { + //获取相对于执行文件的工作目录的绝对路径,并且把路径设置为工作目录 + if err := os.Chdir(filepath.Dir(os.Args[0])); err != nil { + log.Fatal("设置工作目录失败:", err) + } +} func GetChiRouter() *chi.Mux { if chiRouter == nil { @@ -37,8 +43,8 @@ func GetChiRouter() *chi.Mux { return chiRouter } func Run() { - path, _ := GetCurrentPath() - os.Chdir(path) + path, _ := os.Getwd() + log.Println("工作目录:", path) cc := core.GetInstanceConfig()