1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-23 03:50:59 +00:00

panic if parse failed

This commit is contained in:
Pengfei Xue 2013-12-04 23:53:36 +08:00
parent fb6312a303
commit 420e816bed
2 changed files with 37 additions and 9 deletions

View File

@ -71,9 +71,8 @@ func Run() {
if AppConfigPath != path.Join(AppPath, "conf", "app.conf") { if AppConfigPath != path.Join(AppPath, "conf", "app.conf") {
err := ParseConfig() err := ParseConfig()
if err != nil { if err != nil {
if RunMode == "dev" { // configuration is critical to app, panic here if parse failed
Warn(err) panic(err)
}
} }
} }

View File

@ -59,18 +59,32 @@ var (
) )
func init() { func init() {
os.Chdir(path.Dir(os.Args[0])) // create beeapp
BeeApp = NewApp() BeeApp = NewApp()
// initialize default configurations
os.Chdir(path.Dir(os.Args[0]))
AppPath = path.Dir(os.Args[0]) AppPath = path.Dir(os.Args[0])
StaticDir = make(map[string]string) StaticDir = make(map[string]string)
StaticDir["/static"] = "static"
TemplateCache = make(map[string]*template.Template) 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 HttpPort = 8080
AppName = "beego" AppName = "beego"
RunMode = "dev" //default runmod RunMode = "dev" //default runmod
AutoRender = true AutoRender = true
RecoverPanic = true RecoverPanic = true
ViewsPath = "views" ViewsPath = "views"
SessionOn = false SessionOn = false
SessionProvider = "memory" SessionProvider = "memory"
SessionName = "beegosessionID" SessionName = "beegosessionID"
@ -79,23 +93,38 @@ func init() {
SessionHashFunc = "sha1" SessionHashFunc = "sha1"
SessionHashKey = "beegoserversessionkey" SessionHashKey = "beegoserversessionkey"
SessionCookieLifeTime = 3600 SessionCookieLifeTime = 3600
UseFcgi = false UseFcgi = false
MaxMemory = 1 << 26 //64MB MaxMemory = 1 << 26 //64MB
EnableGzip = false EnableGzip = false
StaticDir["/static"] = "static"
AppConfigPath = path.Join(AppPath, "conf", "app.conf") AppConfigPath = path.Join(AppPath, "conf", "app.conf")
HttpServerTimeOut = 0 HttpServerTimeOut = 0
ErrorsShow = true ErrorsShow = true
XSRFKEY = "beegoxsrf" XSRFKEY = "beegoxsrf"
XSRFExpire = 0 XSRFExpire = 0
TemplateLeft = "{{" TemplateLeft = "{{"
TemplateRight = "}}" TemplateRight = "}}"
BeegoServerName = "beegoServer" BeegoServerName = "beegoServer"
EnableAdmin = true EnableAdmin = true
AdminHttpAddr = "localhost" AdminHttpAddr = "127.0.0.1"
AdminHttpPort = 8088 AdminHttpPort = 8088
ParseConfig()
runtime.GOMAXPROCS(runtime.NumCPU()) 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) { func ParseConfig() (err error) {