-
Notifications
You must be signed in to change notification settings - Fork 8k
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
form post, bind to pointer in struct failed #893
Comments
Can you provide an example of the value you posted and the output you got? I can say for 100% certainty that validator supports pointers. |
@joeybloggs , thx for your reply, but I think this is not the validator's fault. Below is an example reproduce the case. I said using validator.v9 was to clarify that the required tag is correct... use httpie to post a form, ~ ❯❯❯ http --verbose --form post localhost:9090 x=1
POST / HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 3
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Host: localhost:9090
User-Agent: HTTPie/0.9.3
x=1
HTTP/1.1 200 OK
Content-Length: 0
Content-Type: text/plain; charset=utf-8
Date: Mon, 24 Apr 2017 02:42:11 GMT
get the following error
Unknown type is reported by gin/binding/form_mapping.go
Because the valueKind is reflect.Ptr. |
I see @cch123 I don't know if the gin team has plans to add support, but if you or the gin team is interested in adding I also have a library that will handle just about anything you can throw at it https://github.com/go-playground/form. I propose that the form decoding is made a configurable interface, just like validator, to allow for plugging in different or more robust libraries. |
@cch123 I run your code using the command
@joeybloggs I used |
@thinkerou , gin's original form binding(not the binding tag, here the binding uses the tag "form" in the struct field tags) does not support mapping form request data to pointer type field of a struct, you can find the form decode part of gin's binding package to confirm that. So even if you update the validator to v9, 'required' validation (here the validation uses the 'binding' tag of the struct, because gin changes the validator's default tag name) of the pointer type field in struct will still fail. |
I did propose a potential solution #893 (comment) if anyone on the Gin team is interested. |
@joeybloggs yes, i'll review it in one/two days, I need to close other issues first, thanks! 😃 |
Implement in #1336 . try it in the latest master branch. right? |
complete demo code is
I've already updated the validator to v9.
Is there any plan to support pointer kind binding?
The text was updated successfully, but these errors were encountered: