1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-16 19:20:54 +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 package beego
import ( import (
"github.com/astaxie/beego/middleware"
"github.com/astaxie/beego/session"
"net/http" "net/http"
"path" "path"
"strings" "strings"
"github.com/astaxie/beego/middleware"
"github.com/astaxie/beego/session"
) )
const VERSION = "0.9.9" 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 { func InsertFilter(pattern string, pos int, filter FilterFunc) *App {
BeeApp.InsertFilter(pattern, pos, filter) BeeApp.InsertFilter(pattern, pos, filter)
return BeeApp return BeeApp
} }
func Run() { func Run() {
//if AppConfigPath not In the conf/app.conf reParse config InitConfig()
if AppConfigPath != path.Join(AppPath, "conf", "app.conf") {
err := ParseConfig()
if err != nil {
if RunMode == "dev" {
Warn(err)
}
}
}
if SessionOn { if SessionOn {
GlobalSessions, _ = session.NewManager(SessionProvider, GlobalSessions, _ = session.NewManager(SessionProvider,

View File

@ -1,14 +1,15 @@
package beego package beego
import ( import (
"github.com/astaxie/beego/config"
"github.com/astaxie/beego/session"
"html/template" "html/template"
"os" "os"
"path" "path"
"runtime" "runtime"
"strconv" "strconv"
"strings" "strings"
"github.com/astaxie/beego/config"
"github.com/astaxie/beego/session"
) )
var ( var (
@ -58,9 +59,9 @@ var (
AdminHttpPort int AdminHttpPort int
) )
func init() { func InitConfig() {
// explicit call config.Init
os.Chdir(path.Dir(os.Args[0])) os.Chdir(path.Dir(os.Args[0]))
BeeApp = NewApp()
AppPath = path.Dir(os.Args[0]) AppPath = path.Dir(os.Args[0])
StaticDir = make(map[string]string) StaticDir = make(map[string]string)
TemplateCache = make(map[string]*template.Template) TemplateCache = make(map[string]*template.Template)
@ -84,7 +85,6 @@ func init() {
MaxMemory = 1 << 26 //64MB MaxMemory = 1 << 26 //64MB
EnableGzip = false EnableGzip = false
StaticDir["/static"] = "static" StaticDir["/static"] = "static"
AppConfigPath = path.Join(AppPath, "conf", "app.conf")
HttpServerTimeOut = 0 HttpServerTimeOut = 0
ErrorsShow = true ErrorsShow = true
XSRFKEY = "beegoxsrf" XSRFKEY = "beegoxsrf"
@ -95,7 +95,17 @@ func init() {
EnableAdmin = true EnableAdmin = true
AdminHttpAddr = "localhost" AdminHttpAddr = "localhost"
AdminHttpPort = 8088 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()) runtime.GOMAXPROCS(runtime.NumCPU())
} }
@ -259,3 +269,7 @@ func ParseConfig() (err error) {
} }
return nil return nil
} }
func init() {
BeeApp = NewApp()
}