Default values (again!!)
Author: ZirboCreated Nov 17, 2023Updated Mar 8, 2025
Hallo,
I know this has been mentioned plenty of times (https://github.com/go-yaml/yaml/issues/462, https://github.com/go-yaml/yaml/issues/165#issuecomment-255223956 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?
Source: go-yaml/yaml