From 420e816beda4ed9a7a61a9b00dea2cdf12f7514c Mon Sep 17 00:00:00 2001 From: Pengfei Xue Date: Wed, 4 Dec 2013 23:53:36 +0800 Subject: [PATCH] panic if parse failed --- beego.go | 7 +++---- config.go | 39 ++++++++++++++++++++++++++++++++++----- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/beego.go b/beego.go index fa4d9cd0..eaccea90 100644 --- a/beego.go +++ b/beego.go @@ -67,13 +67,12 @@ func InsertFilter(pattern string, pos int, filter FilterFunc) *App { } func Run() { - //if AppConfigPath not In the conf/app.conf reParse config + // 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) - } + // configuration is critical to app, panic here if parse failed + panic(err) } } diff --git a/config.go b/config.go index 2159a338..9fbd12dd 100644 --- a/config.go +++ b/config.go @@ -59,18 +59,32 @@ var ( ) func init() { - os.Chdir(path.Dir(os.Args[0])) + // create beeapp BeeApp = NewApp() + + // initialize default configurations + os.Chdir(path.Dir(os.Args[0])) AppPath = path.Dir(os.Args[0]) + StaticDir = make(map[string]string) + StaticDir["/static"] = "static" + TemplateCache = make(map[string]*template.Template) - HttpAddr = "" + + // set this to 0.0.0.0 to make this app available to externally + HttpAddr = "127.0.0.1" HttpPort = 8080 + AppName = "beego" + RunMode = "dev" //default runmod + AutoRender = true + RecoverPanic = true + ViewsPath = "views" + SessionOn = false SessionProvider = "memory" SessionName = "beegosessionID" @@ -79,23 +93,38 @@ func init() { SessionHashFunc = "sha1" SessionHashKey = "beegoserversessionkey" SessionCookieLifeTime = 3600 + UseFcgi = false + MaxMemory = 1 << 26 //64MB + EnableGzip = false - StaticDir["/static"] = "static" + AppConfigPath = path.Join(AppPath, "conf", "app.conf") + HttpServerTimeOut = 0 + ErrorsShow = true + XSRFKEY = "beegoxsrf" XSRFExpire = 0 + TemplateLeft = "{{" TemplateRight = "}}" + BeegoServerName = "beegoServer" + EnableAdmin = true - AdminHttpAddr = "localhost" + AdminHttpAddr = "127.0.0.1" AdminHttpPort = 8088 - ParseConfig() + runtime.GOMAXPROCS(runtime.NumCPU()) + + err := ParseConfig() + if err != nil && !os.IsNotExist(err) { + // panic unless the err is can not find default configuration file + panic(err) + } } func ParseConfig() (err error) {