From a06e0f27ad3b20fb872b28eb73720d9ded2375cf Mon Sep 17 00:00:00 2001 From: Bill Davis Date: Wed, 8 Oct 2014 15:00:07 -0400 Subject: [PATCH 1/2] Support run mode set by env var BEEGO_RUNMODE --- config.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/config.go b/config.go index ef201ec6..314e91b2 100644 --- a/config.go +++ b/config.go @@ -26,6 +26,7 @@ import ( "github.com/astaxie/beego/logs" "github.com/astaxie/beego/session" "github.com/astaxie/beego/utils" + "github.com/kelseyhightower/envconfig" ) var ( @@ -83,9 +84,14 @@ var ( RouterCaseSensitive bool // router case sensitive default is true ) -type beegoAppConfig struct { - innerConfig config.ConfigContainer -} +type ( + beegoAppConfig struct { + innerConfig config.ConfigContainer + } + beegoEnvConfig struct { + RunMode string + } +) func newAppConfig(AppConfigProvider, AppConfigPath string) *beegoAppConfig { ac, err := config.NewConfig(AppConfigProvider, AppConfigPath) @@ -288,8 +294,16 @@ func init() { func ParseConfig() (err error) { AppConfig = newAppConfig(AppConfigProvider, AppConfigPath) + var ec beegoEnvConfig + err = envconfig.Process("beego", &ec) + if err != nil { + return err + } + // set the runmode first - if runmode := AppConfig.String("RunMode"); runmode != "" { + if ec.RunMode != "" { + RunMode = ec.RunMode + } else if runmode := AppConfig.String("RunMode"); runmode != "" { RunMode = runmode } From a27f5c0dc0dbd33ac3239b0066d11711a7a24855 Mon Sep 17 00:00:00 2001 From: Bill Davis Date: Thu, 9 Oct 2014 09:17:10 -0400 Subject: [PATCH 2/2] Remove dependency of third party lib --- config.go | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/config.go b/config.go index 314e91b2..ea02c54e 100644 --- a/config.go +++ b/config.go @@ -26,7 +26,6 @@ import ( "github.com/astaxie/beego/logs" "github.com/astaxie/beego/session" "github.com/astaxie/beego/utils" - "github.com/kelseyhightower/envconfig" ) var ( @@ -84,14 +83,9 @@ var ( RouterCaseSensitive bool // router case sensitive default is true ) -type ( - beegoAppConfig struct { - innerConfig config.ConfigContainer - } - beegoEnvConfig struct { - RunMode string - } -) +type beegoAppConfig struct { + innerConfig config.ConfigContainer +} func newAppConfig(AppConfigProvider, AppConfigPath string) *beegoAppConfig { ac, err := config.NewConfig(AppConfigProvider, AppConfigPath) @@ -294,15 +288,10 @@ func init() { func ParseConfig() (err error) { AppConfig = newAppConfig(AppConfigProvider, AppConfigPath) - var ec beegoEnvConfig - err = envconfig.Process("beego", &ec) - if err != nil { - return err - } - + envRunMode := os.Getenv("BEEGO_RUNMODE") // set the runmode first - if ec.RunMode != "" { - RunMode = ec.RunMode + if envRunMode != "" { + RunMode = envRunMode } else if runmode := AppConfig.String("RunMode"); runmode != "" { RunMode = runmode }