goccy / go-yaml

YAML support for the Go language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add option to support mandatory field when decode

goyzhang opened this issue · comments

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.