cfc604b5 by astaxie

Merge pull request #333 from pengfei-xue/devel

panic if parse failed
2 parents fb6312a3 420e816b
...@@ -67,13 +67,12 @@ func InsertFilter(pattern string, pos int, filter FilterFunc) *App { ...@@ -67,13 +67,12 @@ func InsertFilter(pattern string, pos int, filter FilterFunc) *App {
67 } 67 }
68 68
69 func Run() { 69 func Run() {
70 //if AppConfigPath not In the conf/app.conf reParse config 70 // if AppConfigPath not In the conf/app.conf reParse config
71 if AppConfigPath != path.Join(AppPath, "conf", "app.conf") { 71 if AppConfigPath != path.Join(AppPath, "conf", "app.conf") {
72 err := ParseConfig() 72 err := ParseConfig()
73 if err != nil { 73 if err != nil {
74 if RunMode == "dev" { 74 // configuration is critical to app, panic here if parse failed
75 Warn(err) 75 panic(err)
76 }
77 } 76 }
78 } 77 }
79 78
......
...@@ -59,18 +59,32 @@ var ( ...@@ -59,18 +59,32 @@ var (
59 ) 59 )
60 60
61 func init() { 61 func init() {
62 os.Chdir(path.Dir(os.Args[0])) 62 // create beeapp
63 BeeApp = NewApp() 63 BeeApp = NewApp()
64
65 // initialize default configurations
66 os.Chdir(path.Dir(os.Args[0]))
64 AppPath = path.Dir(os.Args[0]) 67 AppPath = path.Dir(os.Args[0])
68
65 StaticDir = make(map[string]string) 69 StaticDir = make(map[string]string)
70 StaticDir["/static"] = "static"
71
66 TemplateCache = make(map[string]*template.Template) 72 TemplateCache = make(map[string]*template.Template)
67 HttpAddr = "" 73
74 // set this to 0.0.0.0 to make this app available to externally
75 HttpAddr = "127.0.0.1"
68 HttpPort = 8080 76 HttpPort = 8080
77
69 AppName = "beego" 78 AppName = "beego"
79
70 RunMode = "dev" //default runmod 80 RunMode = "dev" //default runmod
81
71 AutoRender = true 82 AutoRender = true
83
72 RecoverPanic = true 84 RecoverPanic = true
85
73 ViewsPath = "views" 86 ViewsPath = "views"
87
74 SessionOn = false 88 SessionOn = false
75 SessionProvider = "memory" 89 SessionProvider = "memory"
76 SessionName = "beegosessionID" 90 SessionName = "beegosessionID"
...@@ -79,23 +93,38 @@ func init() { ...@@ -79,23 +93,38 @@ func init() {
79 SessionHashFunc = "sha1" 93 SessionHashFunc = "sha1"
80 SessionHashKey = "beegoserversessionkey" 94 SessionHashKey = "beegoserversessionkey"
81 SessionCookieLifeTime = 3600 95 SessionCookieLifeTime = 3600
96
82 UseFcgi = false 97 UseFcgi = false
98
83 MaxMemory = 1 << 26 //64MB 99 MaxMemory = 1 << 26 //64MB
100
84 EnableGzip = false 101 EnableGzip = false
85 StaticDir["/static"] = "static" 102
86 AppConfigPath = path.Join(AppPath, "conf", "app.conf") 103 AppConfigPath = path.Join(AppPath, "conf", "app.conf")
104
87 HttpServerTimeOut = 0 105 HttpServerTimeOut = 0
106
88 ErrorsShow = true 107 ErrorsShow = true
108
89 XSRFKEY = "beegoxsrf" 109 XSRFKEY = "beegoxsrf"
90 XSRFExpire = 0 110 XSRFExpire = 0
111
91 TemplateLeft = "{{" 112 TemplateLeft = "{{"
92 TemplateRight = "}}" 113 TemplateRight = "}}"
114
93 BeegoServerName = "beegoServer" 115 BeegoServerName = "beegoServer"
116
94 EnableAdmin = true 117 EnableAdmin = true
95 AdminHttpAddr = "localhost" 118 AdminHttpAddr = "127.0.0.1"
96 AdminHttpPort = 8088 119 AdminHttpPort = 8088
97 ParseConfig() 120
98 runtime.GOMAXPROCS(runtime.NumCPU()) 121 runtime.GOMAXPROCS(runtime.NumCPU())
122
123 err := ParseConfig()
124 if err != nil && !os.IsNotExist(err) {
125 // panic unless the err is can not find default configuration file
126 panic(err)
127 }
99 } 128 }
100 129
101 func ParseConfig() (err error) { 130 func ParseConfig() (err error) {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!