5505cc09 by asta.xie

beego: move init to a fund & add a new fund TestBeegoInit

support Test with everything init
1 parent 12e1ab0f
Showing 1 changed file with 17 additions and 5 deletions
...@@ -2,6 +2,7 @@ package beego ...@@ -2,6 +2,7 @@ package beego
2 2
3 import ( 3 import (
4 "net/http" 4 "net/http"
5 "os"
5 "path" 6 "path"
6 "path/filepath" 7 "path/filepath"
7 "strconv" 8 "strconv"
...@@ -174,6 +175,16 @@ func AddAPPStartHook(hf hookfunc) { ...@@ -174,6 +175,16 @@ func AddAPPStartHook(hf hookfunc) {
174 // Run beego application. 175 // Run beego application.
175 // it's alias of App.Run. 176 // it's alias of App.Run.
176 func Run() { 177 func Run() {
178 initBeforeHttpRun()
179
180 if EnableAdmin {
181 go BeeAdminApp.Run()
182 }
183
184 BeeApp.Run()
185 }
186
187 func initBeforeHttpRun() {
177 // if AppConfigPath not In the conf/app.conf reParse config 188 // if AppConfigPath not In the conf/app.conf reParse config
178 if AppConfigPath != filepath.Join(AppPath, "conf", "app.conf") { 189 if AppConfigPath != filepath.Join(AppPath, "conf", "app.conf") {
179 err := ParseConfig() 190 err := ParseConfig()
...@@ -222,12 +233,13 @@ func Run() { ...@@ -222,12 +233,13 @@ func Run() {
222 middleware.VERSION = VERSION 233 middleware.VERSION = VERSION
223 middleware.AppName = AppName 234 middleware.AppName = AppName
224 middleware.RegisterErrorHandler() 235 middleware.RegisterErrorHandler()
236 }
225 237
226 if EnableAdmin { 238 func TestBeegoInit(apppath string) {
227 go BeeAdminApp.Run() 239 AppPath = apppath
228 } 240 AppConfigPath = filepath.Join(AppPath, "conf", "app.conf")
229 241 os.Chdir(AppPath)
230 BeeApp.Run() 242 initBeforeHttpRun()
231 } 243 }
232 244
233 func init() { 245 func init() {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!