Skip to content

Commit

Permalink
read config by env
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyofx committed Aug 12, 2020
1 parent b1926f7 commit 08732bc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Abstractions/Configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ func NewConfiguration(configContext *ConfigurationContext) *Configuration {
if profile != nil {
profileConfig = viper.New()
profileConfig.AddConfigPath(".")
profileConfig.SetConfigName(configContext.configName + "_" + profile.(string))
configContext.profile = profile.(string)
profileConfig.SetConfigName(configContext.configName + "_" + configContext.profile)
profileConfig.SetConfigType(configContext.configType)
configs := defaultConfig.AllSettings()
// 将default中的配置全部以默认配置写入
Expand All @@ -49,7 +50,7 @@ func (c *Configuration) Get(name string) interface{} {

func (c *Configuration) GetSection(name string) IConfiguration {
section := c.config.Sub(name)

section.SetConfigName(c.context.configName + "_" + c.context.profile)
configs := c.config.AllSettings()
// 将default中的配置全部以默认配置写入
for k, v := range configs {
Expand Down
1 change: 1 addition & 0 deletions Abstractions/ConfigurationBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type ConfigurationContext struct {
enableEnv bool
configType string
configName string
profile string
}

type ConfigurationBuilder struct {
Expand Down

0 comments on commit 08732bc

Please sign in to comment.