From 4df637172bebcd29f40e3928ecfa69d6c8df2bb4 Mon Sep 17 00:00:00 2001 From: zicla Date: Mon, 1 Apr 2019 02:29:46 +0800 Subject: [PATCH] change the path util things. --- .gitignore | 3 ++- rest/install_controller.go | 2 +- rest/util_path.go | 24 ++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 52ab6d4..1f1b939 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ #idea file .idea -dist \ No newline at end of file +dist +tmp \ No newline at end of file diff --git a/rest/install_controller.go b/rest/install_controller.go index ff3ce3e..61a97d9 100644 --- a/rest/install_controller.go +++ b/rest/install_controller.go @@ -102,7 +102,7 @@ func (this *InstallController) openDbConnection(writer http.ResponseWriter, requ db, err := gorm.Open("mysql", mysqlUrl) this.PanicError(err) - db.LogMode(true) + db.LogMode(false) return db diff --git a/rest/util_path.go b/rest/util_path.go index b91fd84..7beddf2 100644 --- a/rest/util_path.go +++ b/rest/util_path.go @@ -2,8 +2,11 @@ package rest import ( "fmt" + "go/build" "os" + "os/user" "path/filepath" + "strings" "time" ) @@ -19,6 +22,13 @@ func PathExists(path string) (bool, error) { return false, err } +//获取GOPATH路径 +func GetGoPath() string { + + return build.Default.GOPATH + +} + //获取该应用可执行文件的位置。 //例如:C:\Users\lishuang\AppData\Local\Temp func GetHomePath() string { @@ -27,6 +37,20 @@ func GetHomePath() string { panic(err) } exPath := filepath.Dir(ex) + + //如果exPath中包含了 /private/var/folders 我们认为是在Mac的开发环境中 + macDev := strings.HasPrefix(exPath, "/private/var/folders") + if macDev { + exPath = GetGoPath() + "/src/tank/tmp" + } + + //如果exPath中包含了 \\AppData\\Local\\Temp 我们认为是在Win的开发环境中 + systemUser, err := user.Current() + winDev := strings.HasPrefix(exPath, systemUser.HomeDir+"\\AppData\\Local\\Temp") + if winDev { + exPath = GetGoPath() + "/src/tank/tmp" + } + return exPath }