add workPath don't chdir when go run or go test
Showing
1 changed file
with
14 additions
and
3 deletions
| ... | @@ -11,12 +11,14 @@ import ( | ... | @@ -11,12 +11,14 @@ import ( |
| 11 | "github.com/astaxie/beego/config" | 11 | "github.com/astaxie/beego/config" |
| 12 | "github.com/astaxie/beego/logs" | 12 | "github.com/astaxie/beego/logs" |
| 13 | "github.com/astaxie/beego/session" | 13 | "github.com/astaxie/beego/session" |
| 14 | "github.com/astaxie/beego/utils" | ||
| 14 | ) | 15 | ) |
| 15 | 16 | ||
| 16 | var ( | 17 | var ( |
| 17 | BeeApp *App // beego application | 18 | BeeApp *App // beego application |
| 18 | AppName string | 19 | AppName string |
| 19 | AppPath string | 20 | AppPath string |
| 21 | workPath string | ||
| 20 | AppConfigPath string | 22 | AppConfigPath string |
| 21 | StaticDir map[string]string | 23 | StaticDir map[string]string |
| 22 | TemplateCache map[string]*template.Template // template caching map | 24 | TemplateCache map[string]*template.Template // template caching map |
| ... | @@ -66,9 +68,20 @@ func init() { | ... | @@ -66,9 +68,20 @@ func init() { |
| 66 | // create beego application | 68 | // create beego application |
| 67 | BeeApp = NewApp() | 69 | BeeApp = NewApp() |
| 68 | 70 | ||
| 71 | workPath, _ = os.Getwd() | ||
| 72 | workPath, _ = filepath.Abs(workPath) | ||
| 69 | // initialize default configurations | 73 | // initialize default configurations |
| 70 | AppPath, _ = filepath.Abs(filepath.Dir(os.Args[0])) | 74 | AppPath, _ = filepath.Abs(filepath.Dir(os.Args[0])) |
| 71 | os.Chdir(AppPath) | 75 | |
| 76 | AppConfigPath = filepath.Join(AppPath, "conf", "app.conf") | ||
| 77 | |||
| 78 | if workPath != AppPath { | ||
| 79 | if utils.FileExists(AppConfigPath) { | ||
| 80 | os.Chdir(AppPath) | ||
| 81 | } else { | ||
| 82 | AppConfigPath = filepath.Join(workPath, "conf", "app.conf") | ||
| 83 | } | ||
| 84 | } | ||
| 72 | 85 | ||
| 73 | StaticDir = make(map[string]string) | 86 | StaticDir = make(map[string]string) |
| 74 | StaticDir["/static"] = "static" | 87 | StaticDir["/static"] = "static" |
| ... | @@ -107,8 +120,6 @@ func init() { | ... | @@ -107,8 +120,6 @@ func init() { |
| 107 | 120 | ||
| 108 | EnableGzip = false | 121 | EnableGzip = false |
| 109 | 122 | ||
| 110 | AppConfigPath = filepath.Join(AppPath, "conf", "app.conf") | ||
| 111 | |||
| 112 | HttpServerTimeOut = 0 | 123 | HttpServerTimeOut = 0 |
| 113 | 124 | ||
| 114 | ErrorsShow = true | 125 | ErrorsShow = true | ... | ... |
-
Please register or sign in to post a comment