Commit 12ade02f authored by Pengfei Xue's avatar Pengfei Xue

panic if parse config failed

parent ec745693
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,
......
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()
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment