From bf0b1af64fc2f87049222cc53bf61ee4dcc5f27a Mon Sep 17 00:00:00 2001 From: "asta.xie" Date: Tue, 1 Apr 2014 18:08:00 +0800 Subject: [PATCH] add workPath don't chdir when go run or go test --- config.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/config.go b/config.go index 54de325c..a963ac02 100644 --- a/config.go +++ b/config.go @@ -11,12 +11,14 @@ import ( "github.com/astaxie/beego/config" "github.com/astaxie/beego/logs" "github.com/astaxie/beego/session" + "github.com/astaxie/beego/utils" ) var ( BeeApp *App // beego application AppName string AppPath string + workPath string AppConfigPath string StaticDir map[string]string TemplateCache map[string]*template.Template // template caching map @@ -66,9 +68,20 @@ func init() { // create beego application BeeApp = NewApp() + workPath, _ = os.Getwd() + workPath, _ = filepath.Abs(workPath) // initialize default configurations AppPath, _ = filepath.Abs(filepath.Dir(os.Args[0])) - os.Chdir(AppPath) + + AppConfigPath = filepath.Join(AppPath, "conf", "app.conf") + + if workPath != AppPath { + if utils.FileExists(AppConfigPath) { + os.Chdir(AppPath) + } else { + AppConfigPath = filepath.Join(workPath, "conf", "app.conf") + } + } StaticDir = make(map[string]string) StaticDir["/static"] = "static" @@ -107,8 +120,6 @@ func init() { EnableGzip = false - AppConfigPath = filepath.Join(AppPath, "conf", "app.conf") - HttpServerTimeOut = 0 ErrorsShow = true