From fe9c52fb69b226b177c6ae1732038497cc60c120 Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 7 Sep 2015 19:27:53 +0800 Subject: [PATCH] optimize init admin --- beego.go | 36 ++++++++++++++++-------------------- hooks.go | 7 +++++++ 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/beego.go b/beego.go index b79e0e3f..81df5752 100644 --- a/beego.go +++ b/beego.go @@ -54,27 +54,9 @@ func Run(params ...string) { } } - if EnableAdmin { - go beeAdminApp.Run() - } - BeeApp.Run() } -// this function is for test package init -func TestBeegoInit(apppath string) { - AppPath = apppath - os.Setenv("BEEGO_RUNMODE", "test") - AppConfigPath = filepath.Join(AppPath, "conf", "app.conf") - err := ParseConfig() - if err != nil && !os.IsNotExist(err) { - // for init if doesn't have app.conf will not panic - Info(err) - } - os.Chdir(AppPath) - initBeforeHttpRun() -} - func initBeforeHttpRun() { // if AppConfigPath not In the conf/app.conf reParse config if AppConfigPath != filepath.Join(AppPath, "conf", "app.conf") { @@ -91,12 +73,26 @@ func initBeforeHttpRun() { AddAPPStartHook(registerSession) AddAPPStartHook(registerDocs) AddAPPStartHook(registerTemplate) + AddAPPStartHook(registerAdmin) // do hooks function for _, hk := range hooks { - err := hk() - if err != nil { + if err := hk(); err != nil { panic(err) } } } + +// this function is for test package init +func TestBeegoInit(apppath string) { + AppPath = apppath + os.Setenv("BEEGO_RUNMODE", "test") + AppConfigPath = filepath.Join(AppPath, "conf", "app.conf") + err := ParseConfig() + if err != nil && !os.IsNotExist(err) { + // for init if doesn't have app.conf will not panic + Info(err) + } + os.Chdir(AppPath) + initBeforeHttpRun() +} diff --git a/hooks.go b/hooks.go index ded0d794..78aec636 100644 --- a/hooks.go +++ b/hooks.go @@ -98,3 +98,10 @@ func registerDocs() error { } return nil } + +func registerAdmin() error { + if EnableAdmin { + go beeAdminApp.Run() + } + return nil +}