// MergeConfigOverrides merges current config with overrides loaded from other sources func MergeConfigOverrides(config *confer.Config, configParts map[string]interface{}) error { keys := make([]string, len(configParts)) i := 0 for key := range configParts { keys[i] = key i++ } sort.Strings(keys) for _, key := range keys { log.Printf("Merging overrides from key %s...", key) err := config.MergeAttributes(configParts[key]) if err != nil { return fmt.Errorf("unable to merge data for key %s (data %#v): %s", key, configParts[key], err) } } return nil }
// NewConsulFromConfig initializes Consul client based on config + environment overrides func NewConsulFromConfig(config *confer.Config, configPrefix string) (client *api.Client, consulPrefix string, err error) { upperPrefix := strings.ToUpper(configPrefix) config.BindEnv(upperPrefix+"_ENABLED", configPrefix+".enabled") config.BindEnv(upperPrefix+"_SCHEME", configPrefix+".scheme") config.BindEnv(upperPrefix+"_ADDRESS", configPrefix+".address") config.BindEnv(upperPrefix+"_PREFIX", configPrefix+".prefix") config.BindEnv(upperPrefix+"_TOKEN", configPrefix+".token") if !config.GetBool(configPrefix + ".enabled") { // Consul is disabled return } conf := api.DefaultConfig() conf.Scheme = config.GetString(configPrefix + ".scheme") conf.Address = config.GetString(configPrefix + ".address") conf.Token = config.GetString(configPrefix + ".token") consulPrefix = config.GetString(configPrefix + ".prefix") client, err = api.NewClient(conf) return }