From 12ade02f2de897f2fd84ee0ae0dd5af0217cd25a Mon Sep 17 00:00:00 2001 From: Pengfei Xue Date: Tue, 3 Dec 2013 19:26:51 +0800 Subject: [PATCH] panic if parse config failed --- beego.go | 20 ++++++-------------- config.go | 26 ++++++++++++++++++++------ 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/beego.go b/beego.go index 32fdffd0..61b6d823 100644 --- a/beego.go +++ b/beego.go @@ -1,11 +1,12 @@ package beego import ( - "github.com/astaxie/beego/middleware" - "github.com/astaxie/beego/session" "net/http" "path" "strings" + + "github.com/astaxie/beego/middleware" + "github.com/astaxie/beego/session" ) const VERSION = "0.9.9" @@ -61,21 +62,12 @@ func AddFilter(pattern, action string, filter FilterFunc) *App { } func InsertFilter(pattern string, pos int, filter FilterFunc) *App { - BeeApp.InsertFilter(pattern, pos, filter) - return BeeApp + BeeApp.InsertFilter(pattern, pos, filter) + return BeeApp } - func Run() { - //if AppConfigPath not In the conf/app.conf reParse config - if AppConfigPath != path.Join(AppPath, "conf", "app.conf") { - err := ParseConfig() - if err != nil { - if RunMode == "dev" { - Warn(err) - } - } - } + InitConfig() if SessionOn { GlobalSessions, _ = session.NewManager(SessionProvider, diff --git a/config.go b/config.go index 942e6fb8..32370d60 100644 --- a/config.go +++ b/config.go @@ -1,14 +1,15 @@ package beego import ( - "github.com/astaxie/beego/config" - "github.com/astaxie/beego/session" "html/template" "os" "path" "runtime" "strconv" "strings" + + "github.com/astaxie/beego/config" + "github.com/astaxie/beego/session" ) var ( @@ -58,9 +59,9 @@ var ( AdminHttpPort int ) -func init() { +func InitConfig() { + // explicit call config.Init os.Chdir(path.Dir(os.Args[0])) - BeeApp = NewApp() AppPath = path.Dir(os.Args[0]) StaticDir = make(map[string]string) TemplateCache = make(map[string]*template.Template) @@ -84,7 +85,6 @@ func init() { MaxMemory = 1 << 26 //64MB EnableGzip = false StaticDir["/static"] = "static" - AppConfigPath = path.Join(AppPath, "conf", "app.conf") HttpServerTimeOut = 0 ErrorsShow = true XSRFKEY = "beegoxsrf" @@ -95,7 +95,17 @@ func init() { EnableAdmin = true AdminHttpAddr = "localhost" AdminHttpPort = 8088 - ParseConfig() + + // if AppConfigPath hasn't been set yet, + // use /Path/to/AppPath/conf/app.conf as the default + if AppConfigPath == "" { + AppConfigPath = path.Join(AppPath, "conf", "app.conf") + } + + if err := ParseConfig(); err != nil { + panic(err) + } + runtime.GOMAXPROCS(runtime.NumCPU()) } @@ -259,3 +269,7 @@ func ParseConfig() (err error) { } return nil } + +func init() { + BeeApp = NewApp() +}