Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e.VIper.ReadInConfig run as part of Unmarshal clears merged in fields #12

Closed
jkosecki opened this issue Nov 6, 2022 · 1 comment
Closed

Comments

@jkosecki
Copy link

jkosecki commented Nov 6, 2022

Hi,

due to e.Viper.ReadInConfig() that is invoked as part of Enviper#Unmarshal any additional fields added via Viper#MergeConfigMap method are cleared. That prevents usage like that:

        e := enviper.New(viper.New())
	if err := e.ReadInConfig(); err != nil {
		panic(err.Error())
	}
	if err := e.MergeConfigMap(defaults.AllSettings()); err != nil {
		panic(err.Error())
	}
	if err := e.Unmarshal(&cfg); err != nil {
		panic(err.Error())
	}

Is there a reason why Unmarshal makes a call to ReadInConfig? Afaik, viper itself expects users to call ReadInConfig explicitly before Unmarshal is used

@iamolegga
Copy link
Owner

This was in original solution. I actually don't remember why is this required. You could fork this repo, drop that line and run tests and see if it will work for you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants