diff --git a/Abstractions/Configuration.go b/Abstractions/Configuration.go index 7917c1df..6147bc77 100644 --- a/Abstractions/Configuration.go +++ b/Abstractions/Configuration.go @@ -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中的配置全部以默认配置写入 @@ -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 { diff --git a/Abstractions/ConfigurationBuilder.go b/Abstractions/ConfigurationBuilder.go index bac76327..d55e5e5d 100644 --- a/Abstractions/ConfigurationBuilder.go +++ b/Abstractions/ConfigurationBuilder.go @@ -5,6 +5,7 @@ type ConfigurationContext struct { enableEnv bool configType string configName string + profile string } type ConfigurationBuilder struct {