Skip to content
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

add len,min,max,regex... support for pointer type #50

Merged
merged 2 commits into from
Feb 5, 2018

Conversation

YueHonghui
Copy link
Contributor

In our project, we use struct contains pointer type variables to distinct between empty and nil value. But validator not supported pointer type couldn't satisfy this situation. So I implement len,min,max,regex... builtin validators for elem of pointer types.

Request to merge.

@jameshartig
Copy link
Collaborator

I'm not sure what we should do about the nil problem. Off the top of my head: length should be 0 for nil, and maybe the same with min/max and then for regex maybe don't return an error. Either way we should document in the function doc what happens with nil pointers. I would also be fine saying that they're not handled (like you have now) and you have to use nonzero if you don't want to accept nil.

@YueHonghui
Copy link
Contributor Author

Yes, you are right. In this PR, I just omit the nil pointer, leave it to the nonzero validator. The validators separated by , in tags, actually represents expression validator1 and validator2 and validator3. If validators other than nonzero can handle nil as False, we would have no way to represent expression zero or validator. I will update the PR with a better doc to this.

@jameshartig jameshartig merged commit 59c90c7 into go-validator:v2 Feb 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants