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

[Feature Request] Ability to set validator #8

Closed
nvcnvn opened this issue Jun 19, 2013 · 6 comments
Closed

[Feature Request] Ability to set validator #8

nvcnvn opened this issue Jun 19, 2013 · 6 comments

Comments

@nvcnvn
Copy link

nvcnvn commented Jun 19, 2013

Hi, first thank for your great toolkit!
I'm using gorilla/schema in my app and I hope it can help me with some simple validate.
For example, with s struct:

type Foo struct {
  X string `schema:",url"`
  Y string `schema:",email"`
}

And then given a map of Validator

var validators = map[string]func([]string) error {
  "email":func(ss []string) error {/*...*/},
}

We can decode and check validate error easily.
Thanks

P/s: If you don't have time or maybe this request not suit to the pkg, I hope you can show me some tip to start it myself.

@kisielk
Copy link
Contributor

kisielk commented Jul 9, 2013

I don't really see the motivation. How is it easier than just validating the value of Foo after it has been decoded?

@nvcnvn
Copy link
Author

nvcnvn commented Jul 9, 2013

Yes, not much but ...some convenience...
For example you can add the error from validtaor to the MultiError list.
And then we can provide some default validator for user with some thing similar with JQuery Validator plugin etc...

P/s: It sound not as that good but when I use ASP.NET they provide something like that...and some how I miss them :D

@kisielk
Copy link
Contributor

kisielk commented Jul 9, 2013

Right, so the main purpose would be so the errors show up in the MultiError list ?

@kisielk
Copy link
Contributor

kisielk commented Jul 9, 2013

Also do you have a link to the docs for the ASP.NET version? Would be curious to see how theirs works.

@nvcnvn
Copy link
Author

nvcnvn commented Jul 9, 2013

Yes, we can say the main purpose is "helping lazy one" 😄
In ASP.NET MVC they have some attributes for model class, you can find for "[Required]" example in this link
http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/adding-validation-to-the-model
(I think Go struct tags can be an alternative for Java Annotations or C# Attributes?)

@kisielk
Copy link
Contributor

kisielk commented Aug 11, 2015

I definitely don't want to invent some kind of microlanguage in struct tags for validation, so I think that's out. It seems to me that giving schema the ability to register some kind of callback validator to be called upon decode isn't much better than simply calling a validation function after decoding has been completed. I'm willing to be convinced otherwise, but closing this for now.

@kisielk kisielk closed this as completed Aug 11, 2015
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

No branches or pull requests

2 participants