panic if parse config failed
Showing
2 changed files
with
24 additions
and
18 deletions
| 1 | package beego | 1 | package beego |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "github.com/astaxie/beego/middleware" | ||
| 5 | "github.com/astaxie/beego/session" | ||
| 6 | "net/http" | 4 | "net/http" |
| 7 | "path" | 5 | "path" |
| 8 | "strings" | 6 | "strings" |
| 7 | |||
| 8 | "github.com/astaxie/beego/middleware" | ||
| 9 | "github.com/astaxie/beego/session" | ||
| 9 | ) | 10 | ) |
| 10 | 11 | ||
| 11 | const VERSION = "0.9.9" | 12 | const VERSION = "0.9.9" |
| ... | @@ -65,17 +66,8 @@ func InsertFilter(pattern string, pos int, filter FilterFunc) *App { | ... | @@ -65,17 +66,8 @@ func InsertFilter(pattern string, pos int, filter FilterFunc) *App { |
| 65 | return BeeApp | 66 | return BeeApp |
| 66 | } | 67 | } |
| 67 | 68 | ||
| 68 | |||
| 69 | func Run() { | 69 | func Run() { |
| 70 | //if AppConfigPath not In the conf/app.conf reParse config | 70 | InitConfig() |
| 71 | if AppConfigPath != path.Join(AppPath, "conf", "app.conf") { | ||
| 72 | err := ParseConfig() | ||
| 73 | if err != nil { | ||
| 74 | if RunMode == "dev" { | ||
| 75 | Warn(err) | ||
| 76 | } | ||
| 77 | } | ||
| 78 | } | ||
| 79 | 71 | ||
| 80 | if SessionOn { | 72 | if SessionOn { |
| 81 | GlobalSessions, _ = session.NewManager(SessionProvider, | 73 | GlobalSessions, _ = session.NewManager(SessionProvider, | ... | ... |
| 1 | package beego | 1 | package beego |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "github.com/astaxie/beego/config" | ||
| 5 | "github.com/astaxie/beego/session" | ||
| 6 | "html/template" | 4 | "html/template" |
| 7 | "os" | 5 | "os" |
| 8 | "path" | 6 | "path" |
| 9 | "runtime" | 7 | "runtime" |
| 10 | "strconv" | 8 | "strconv" |
| 11 | "strings" | 9 | "strings" |
| 10 | |||
| 11 | "github.com/astaxie/beego/config" | ||
| 12 | "github.com/astaxie/beego/session" | ||
| 12 | ) | 13 | ) |
| 13 | 14 | ||
| 14 | var ( | 15 | var ( |
| ... | @@ -58,9 +59,9 @@ var ( | ... | @@ -58,9 +59,9 @@ var ( |
| 58 | AdminHttpPort int | 59 | AdminHttpPort int |
| 59 | ) | 60 | ) |
| 60 | 61 | ||
| 61 | func init() { | 62 | func InitConfig() { |
| 63 | // explicit call config.Init | ||
| 62 | os.Chdir(path.Dir(os.Args[0])) | 64 | os.Chdir(path.Dir(os.Args[0])) |
| 63 | BeeApp = NewApp() | ||
| 64 | AppPath = path.Dir(os.Args[0]) | 65 | AppPath = path.Dir(os.Args[0]) |
| 65 | StaticDir = make(map[string]string) | 66 | StaticDir = make(map[string]string) |
| 66 | TemplateCache = make(map[string]*template.Template) | 67 | TemplateCache = make(map[string]*template.Template) |
| ... | @@ -84,7 +85,6 @@ func init() { | ... | @@ -84,7 +85,6 @@ func init() { |
| 84 | MaxMemory = 1 << 26 //64MB | 85 | MaxMemory = 1 << 26 //64MB |
| 85 | EnableGzip = false | 86 | EnableGzip = false |
| 86 | StaticDir["/static"] = "static" | 87 | StaticDir["/static"] = "static" |
| 87 | AppConfigPath = path.Join(AppPath, "conf", "app.conf") | ||
| 88 | HttpServerTimeOut = 0 | 88 | HttpServerTimeOut = 0 |
| 89 | ErrorsShow = true | 89 | ErrorsShow = true |
| 90 | XSRFKEY = "beegoxsrf" | 90 | XSRFKEY = "beegoxsrf" |
| ... | @@ -95,7 +95,17 @@ func init() { | ... | @@ -95,7 +95,17 @@ func init() { |
| 95 | EnableAdmin = true | 95 | EnableAdmin = true |
| 96 | AdminHttpAddr = "localhost" | 96 | AdminHttpAddr = "localhost" |
| 97 | AdminHttpPort = 8088 | 97 | AdminHttpPort = 8088 |
| 98 | ParseConfig() | 98 | |
| 99 | // if AppConfigPath hasn't been set yet, | ||
| 100 | // use /Path/to/AppPath/conf/app.conf as the default | ||
| 101 | if AppConfigPath == "" { | ||
| 102 | AppConfigPath = path.Join(AppPath, "conf", "app.conf") | ||
| 103 | } | ||
| 104 | |||
| 105 | if err := ParseConfig(); err != nil { | ||
| 106 | panic(err) | ||
| 107 | } | ||
| 108 | |||
| 99 | runtime.GOMAXPROCS(runtime.NumCPU()) | 109 | runtime.GOMAXPROCS(runtime.NumCPU()) |
| 100 | } | 110 | } |
| 101 | 111 | ||
| ... | @@ -259,3 +269,7 @@ func ParseConfig() (err error) { | ... | @@ -259,3 +269,7 @@ func ParseConfig() (err error) { |
| 259 | } | 269 | } |
| 260 | return nil | 270 | return nil |
| 261 | } | 271 | } |
| 272 | |||
| 273 | func init() { | ||
| 274 | BeeApp = NewApp() | ||
| 275 | } | ... | ... |
-
Please register or sign in to post a comment