1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-16 17:20:55 +00:00

Merge pull request #330 from pengfei-xue/devel

panic if parse config failed
This commit is contained in:
astaxie 2013-12-03 04:33:08 -08:00
commit 983f20642c
2 changed files with 26 additions and 20 deletions

View File

@ -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,

View File

@ -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()
}