v8 and v9
I was wondering if it's possible to validate unexported fields. But unexported fields are skipped here.
https://github.com/go-playground/validator/blob/v9/cache.go#L131
Is there any reason for it?
@Jwata A package can only view the unexported fields of types within its own package and so they must be ignored or there will be an exception; this is true of all packages using reflect even the son package.
OK, so they must be exported to do validate using reflection.
As far as i know reflect can read an unexported field, but write can't. Check the following link: https://yourbasic.org/golang/access-private-field-reflection/. Also you can use reflect2 package as json-iterator/extra do: https://godoc.org/github.com/json-iterator/go/extra#SupportPrivateFields.
Is there's a way that you considirer validate unexported fields?
Many thanks un advance.
@fuintis thanks for the link, I could have sworn this was not possible but I鈥檒l take another look! love to support unexported fields if I can
Should this issue be reopened ?
It could be handy to have a validation on unexported fields when you want your struct to be immutable.
Same here. This issue completely breaks DDD entity pattern.
Most helpful comment
Should this issue be reopened ?
It could be handy to have a validation on unexported fields when you want your struct to be immutable.