-
-
Notifications
You must be signed in to change notification settings - Fork 179
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
Custom Validation #259
base: main
Are you sure you want to change the base?
Custom Validation #259
Conversation
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.
Thanks for kicking this off! I've just reviewed. I really like where you started with this PR because it would remain generic while still allowing you to stick an existing validator library in there and do something like:
type Input struct {
name string `validate:len>5`
}
var validate = validator.New()
func(i *Input) Validate() error {
return validate.Struct(i)
}
(not sure on exact syntax)
if err := in.Validate(); err != nil { | ||
return &response.Format{ | ||
{{- if ne $action.Method "GET" }} | ||
HTML: response.Status(http.StatusSeeOther).RedirectBack(httpRequest.URL.Path), |
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 big question is going to be what happens with the error message? Right now if a form fails, there's no feedback sent back to the user.
Flash messages are typically the solution to this where you store a value in a cookie that gets removed after it's pulled out. I think the ultimate solution is to have the ability to add custom flash messages via the session, but if there's any temporary solution to get this working where you set the cookie, pull it out and pass to the view, I'd be open to pursuing that. Here's what I've thought about so far with sessions: #56.
Otherwise maybe we only enable this for JSON? Does your use case fit with that limitation?
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.
Yea, I think flash messages should be the behavior here. I'm thinking to add some other stuff to this PR but then put in on pause until we have sessions and something like flash messages.
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.
Cool, sounds good! I'm going to get back to feature development very soon. Just trying to wrap up generator caching to allow for running more expensive generators (e.g. generators that call go run
), so hopefully we'll get sessions soon!
Ok, I'll clean this up. Also, I just re-read the discussion here: #15
|
I changed the name to |
Yah, might be best to wait for sessions. In the meantime, you can always add the validate function to the method body. I'll try and get sessions added soon! |
This implements validation by calling
Validate
when appropriate. There are still several other things to do, so this should be a draft. I am curious what you think of this approach so far.