Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants