goccy / go-yaml

YAML support for the Go language
MIT License
1.12k stars 129 forks source link

Add option to support mandatory field when decode #397

Open goyzhang opened 11 months ago

goyzhang commented 11 months ago

validate:required won't work for input like:

value: 0 # this will fail the validator. But I want value to be mandatory field as well.

Because the validator always check against the struct defaults, however, it's very likely that the input value of an int is 0 and string is "". int -> *int is yet another dirty hack. Since validator check against struct, only the go-yaml is able to detect this error when parsing the string.