Zog v0.15 with support for validating schemas directly (without parsing) to be released this week #66
Oudwins
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey everyone!
I wanted to have gotten this feature out before the end of the holidays but I didn't end up having enough time. But this week I powered through and have it built! Zog 0.15 will come with a new
Validateschema method which will recursively validate a value (struct, slice, etc). Without the need for parsing!You'll now be able to do:
ValidateWill support all existing tests, pretransforms, posttransforms, etc. And should be much faster thanParseLimitations
There two main limitations with the
Validatemethod:1 No support for type coercion. For obvious reasons. So if you need to coerce a data string to a time.Time you will still need to use Parse or coerce the data manually before validation.
2 When Executing a Validation the required test will cause an error if the value is the zero value for its type
The main reason for this is that there is no way for Zog to know if that value was defined or not. And I did not want to add yet another test like
NotZero()to check that the value is not a zero value as that might lead to schemas likez.String().Required().NotZero()if you are using both parse and validate.If you are using validate and want to have a required value that accepts the zero value for its type you can do it like this:
Beta Was this translation helpful? Give feedback.
All reactions