go-yaml / yaml

YAML support for the Go language.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Default values (again!!)

Zirbo opened this issue · comments

Hallo,
I know this has been mentioned plenty of times (#462, #165 (comment) and so on) and that you can implement UnmarshalYAML to set your own defaults.
Buuuuuut if you have multiple types of configs, and in each of them just a single field needs a default, implementing UnmarshalYAML in each of them makes your code quite bloated. It really seems complexity that could be hidden in the library itself.
Is something like

type Config struct {
    A string  `string_name, omitempty, default="abc"`
    B int       `int_name, omitempty, default=10`
    C bool    `bool_name, omitempty, default=true`
}

in the roadmap? Or is there some deeper reason (I mean in the code) for this missing feature so it will never be implemented?

This would be so nice