1
0
mirror of https://github.com/astaxie/beego.git synced 2025-07-11 05:51:00 +00:00

Merge branch 'develop' into config-logic

This commit is contained in:
youngsterxyf
2016-01-27 10:58:38 +08:00
24 changed files with 548 additions and 280 deletions

View File

@ -105,18 +105,25 @@ var (
BConfig *Config
// AppConfig is the instance of Config, store the config information from file
AppConfig *beegoAppConfig
// AppPath is the absolute path to the app
AppPath string
// AppConfigPath is the path to the config files
AppConfigPath string
// AppConfigProvider is the provider for the config, default is ini
AppConfigProvider = "ini"
// TemplateCache stores template caching
TemplateCache map[string]*template.Template
// GlobalSessions is the instance for the session manager
GlobalSessions *session.Manager
// AppConfigPath is the path to the config files
AppConfigPath string
// AppConfigProvider is the provider for the config, default is ini
AppConfigProvider = "ini"
workPath string
)
func init() {
AppPath, _ = filepath.Abs(filepath.Dir(os.Args[0]))
workPath, _ = os.Getwd()
workPath, _ = filepath.Abs(workPath)
BConfig = &Config{
AppName: "beego",
RunMode: DEV,
@ -177,8 +184,7 @@ func init() {
},
}
AppConfigPath = getDefaultAppConfigPath()
AppConfigPath = filepath.Join(AppPath, "conf", "app.conf")
if !utils.FileExists(AppConfigPath) {
AppConfig = &beegoAppConfig{config.NewFakeConfig()}
return
@ -187,14 +193,12 @@ func init() {
parseConfig(AppConfigPath)
}
func getDefaultAppConfigPath() string {
// default config path
AppPath, _ := filepath.Abs(filepath.Dir(os.Args[0]))
return filepath.Join(AppPath, "conf", "app.conf")
}
// now only support ini, next will support json.
func parseConfig(appConfigPath string) (err error) {
if workPath != AppPath {
os.Chdir(AppPath)
}
AppConfig, err = newAppConfig(AppConfigProvider, appConfigPath)
if err != nil {
return err