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

Default value #111

Closed
marczahn opened this issue Mar 27, 2018 · 3 comments
Closed

Default value #111

marczahn opened this issue Mar 27, 2018 · 3 comments

Comments

@marczahn
Copy link

Hi,

is there a way to provide default values for an field?

Sth. like

...
    Field string "mapstructure:"field" mapstructure_default:"A default value"`
...
@kbudde
Copy link

kbudde commented Jun 16, 2019

Hi this would be a quite usefull feature.
Is it possible?

@snowdream
Copy link

I need this feature too.

Is there any news?

@mitchellh
Copy link
Owner

I'm still unsure if mapstructure should take on this additional scope. I usually pair mapstructure with a library such as https://github.com/mcuadros/go-defaults to solve this.

Defaults on their own don't fit super well into the current implementatin of mapstructure because the lib only looks for matching fields based on the data, so we wouldn't even really see the fields marked with "default". So this would quire a considerably different implementation.

I also just merged #183 which should enable this sort of functionality via hooks you may want to take a look at. You should be able to create a hook on structs that calls a defaults library (or does it manually).

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

4 participants