-
Notifications
You must be signed in to change notification settings - Fork 41
Open
Description
I'm reading a single config file where I want to override values based on priority. My initial code below worked with 1.1.0, but does not with 1.3.0. I understand that some functions have been marked deprecated in 1.3.0, but the README explicitly states that "no breaking changes will be made in the 1.x series of releases".
I see that the new NewYAML function can take multiple files with priority, but I want to read and merge a single file. Is there another way to do this in 1.3.0?
Reproduction:
config.yml file:
---
default:
foo: Base
other:
foo: Override
main.go:
package main
import (
"fmt"
"go.uber.org/config"
)
func main() {
var conf struct {
Foo string `yaml:"foo"`
}
provider, err := fromSpecificEnvs("config.yml", "default", "other")
if err != nil {
panic(err)
}
if err := provider.Get(config.Root).Populate(&conf); err != nil {
panic(err)
}
fmt.Printf("Foo: %q\n", conf.Foo)
}
func fromSpecificEnvs(filepath string, envs ...string) (config.Provider, error) {
baseProvider, err := config.NewYAMLProviderFromFiles(filepath)
if err != nil {
return nil, fmt.Errorf("error parsing config file: %v", err)
}
var subProviders []config.Provider
for _, env := range envs {
sp := config.NewScopedProvider(env, baseProvider)
subProviders = append(subProviders, sp)
}
return config.NewProviderGroup("config", subProviders...)
}
Result using 1.1.0:
Foo: "Override"
Result using 1.3.0:
Foo: ""
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels