-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: implement ValidatorValuer interface feature #1416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
7222de7
to
a4b2773
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The good looks good.
My only concerns would maybe be the naming of the interface and it's function.
util.go
Outdated
@@ -9,6 +9,13 @@ import ( | |||
"time" | |||
) | |||
|
|||
// ValidatorValuer is an interface that allows you to expose a method on a type | |||
// (including generic types) that returns a value that is supposed to be validated. | |||
type ValidatorValuer interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can drop the Validator
, Outside this functions it's validator.ValidatorValuer
which stutters.
validator.Valuer
should be fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function name should probably stay ValidatorValue
to not conflict with the sql.Valuer
interface. Consequently, I'd suggest that validator valuer interface should stay ValidatorValuer
to match the function name it expects, but I renamed it to Valuer
anyway. The positive here is that we have validator.Valuer
now which looks cleaner. 👍
a4b2773
to
2996074
Compare
2996074
to
62dc169
Compare
Problem
In order to have custom type validations for generic types, every possible type has to be registered with
RegisterCustomTypeFunc
to return the underlying type. It is especially relevant for nullable types e.g.sql.Null[T]
.Discussed here: #1232
Fixes Or Enhances
ValidatorValuer
interface.Example:
Make sure that you've checked the boxes below before you submit PR:
@go-playground/validator-maintainers