From 5505cc09edb187f54ff8ca4dbde4192c70d1137c Mon Sep 17 00:00:00 2001 From: "asta.xie" Date: Thu, 3 Apr 2014 15:07:20 +0800 Subject: [PATCH] beego: move init to a fund & add a new fund TestBeegoInit support Test with everything init --- beego.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/beego.go b/beego.go index e658c3b5..5efd2d6a 100644 --- a/beego.go +++ b/beego.go @@ -2,6 +2,7 @@ package beego import ( "net/http" + "os" "path" "path/filepath" "strconv" @@ -174,6 +175,16 @@ func AddAPPStartHook(hf hookfunc) { // Run beego application. // it's alias of App.Run. func Run() { + initBeforeHttpRun() + + if EnableAdmin { + go BeeAdminApp.Run() + } + + BeeApp.Run() +} + +func initBeforeHttpRun() { // if AppConfigPath not In the conf/app.conf reParse config if AppConfigPath != filepath.Join(AppPath, "conf", "app.conf") { err := ParseConfig() @@ -222,12 +233,13 @@ func Run() { middleware.VERSION = VERSION middleware.AppName = AppName middleware.RegisterErrorHandler() +} - if EnableAdmin { - go BeeAdminApp.Run() - } - - BeeApp.Run() +func TestBeegoInit(apppath string) { + AppPath = apppath + AppConfigPath = filepath.Join(AppPath, "conf", "app.conf") + os.Chdir(AppPath) + initBeforeHttpRun() } func init() {