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

how about add pointer support in binding Form Params? #1334

Closed
qazqwe1596357 opened this issue Apr 25, 2018 · 4 comments
Closed

how about add pointer support in binding Form Params? #1334

qazqwe1596357 opened this issue Apr 25, 2018 · 4 comments

Comments

@qazqwe1596357
Copy link

qazqwe1596357 commented Apr 25, 2018

I see code in https://github.com/gin-gonic/gin/blob/master/binding/form_mapping.go, we can only support value field bind, do not support pointer type.

// example
type Params struct {
  Pa string `form:"pa"`  // which can success bind via form_mapping
  Pb *string `form:"pb"`  // which cannot bind via form_mapping
}

The reason is fieldKind in "func setWithProperType()" have not pointer type.

Supporting pointer fields bind is useful we can easy know whether we pass the param. if we not passing it, it will keep nil value.
In Json Unmarshal can process pointer field also.

So do you think supporting pointer field parse in binding/form_mapping.go is a good idea?

@ritoon
Copy link

ritoon commented Apr 27, 2018

looks done did you test the new gin version
2282be0#diff-e1ee2d6085c74d622d08bb3927e7036c

@qazqwe1596357
Copy link
Author

The response is too fast! Thanks a lot~

@appleboy
Copy link
Member

Implemented in #1336

@ivanovaleksey
Copy link

Is it possible to differentiate between a boolean pointer parameter being nil, true, or false?
If I don't set the parameter in a query it results to false but I would like it to be nil.
Is there a way to explicitly set pointer parameter to nil?

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

4 participants