From 9d103d3b09661dfe35ceb6943c6982e49a3ca46f Mon Sep 17 00:00:00 2001 From: Tan Jiang Date: Tue, 23 Feb 2016 12:16:36 +0800 Subject: [PATCH] reload config before initialization of controllers --- controllers/base.go | 12 +++++++++++- main.go | 7 ------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/controllers/base.go b/controllers/base.go index 1f95f830e..9f9046b0f 100644 --- a/controllers/base.go +++ b/controllers/base.go @@ -15,6 +15,7 @@ package controllers import ( + "log" "os" "strings" @@ -114,6 +115,16 @@ var langTypes []*langType func init() { + //conf/app.conf -> os.Getenv("config_path") + configPath := os.Getenv("CONFIG_PATH") + if len(configPath) != 0 { + log.Printf("Config path: %s", configPath) + beego.AppConfigPath = configPath + if err := beego.ParseConfig(); err != nil { + beego.Warning("Failed to parse config file: ", configPath, "error: ", err) + } + } + beego.AddFuncMap("i18n", i18n.Tr) langs := strings.Split(beego.AppConfig.String("lang::types"), "|") @@ -134,7 +145,6 @@ func init() { for _, lang := range langs { if err := i18n.SetMessage(lang, "static/i18n/"+"locale_"+lang+".ini"); err != nil { beego.Error("Fail to set message file:" + err.Error()) - return } } } diff --git a/main.go b/main.go index 86e8ee87d..189cb8400 100644 --- a/main.go +++ b/main.go @@ -68,13 +68,6 @@ func main() { beego.BConfig.WebConfig.Session.SessionOn = true - //conf/app.conf -> os.Getenv("config_path") - configPath := os.Getenv("CONFIG_PATH") - if len(configPath) != 0 { - beego.Debug(fmt.Sprintf("Config path: %s", configPath)) - beego.AppConfigPath = configPath - } - updateInitPassword(ADMIN_USER_ID, os.Getenv("HARBOR_ADMIN_PASSWORD")) beego.Run()