1
0
mirror of https://github.com/astaxie/beego.git synced 2024-12-22 23:40:50 +00:00

optimize init admin

This commit is contained in:
astaxie 2015-09-07 19:27:53 +08:00
parent 284dfc0843
commit fe9c52fb69
2 changed files with 23 additions and 20 deletions

View File

@ -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()
}

View File

@ -98,3 +98,10 @@ func registerDocs() error {
}
return nil
}
func registerAdmin() error {
if EnableAdmin {
go beeAdminApp.Run()
}
return nil
}