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

gin binding helper improved #3

Closed
LaysDragon opened this issue Oct 15, 2020 · 0 comments
Closed

gin binding helper improved #3

LaysDragon opened this issue Oct 15, 2020 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@LaysDragon
Copy link
Member

now gin have problem to deal with custom format time form application/x-www-form-urlencoded.
That curse the problem to binding with gin's implementation for current version, even a pull request have already sent. but it still need a better way to deal with this for older version even the new version come out with fix.
Checkout the detail here gin-gonic/gin#2510

It would better to use regex to replace and quoted the certain time string in the data instead of decode and encode complete.

func QuotedAndBindingData(data interface{}, quotedfields []string, c *gin.Context) error {
body, err := c.GetRawData()
if err != nil {
return err
}
c.Request.Body = ioutil.NopCloser(bytes.NewBuffer(body))
err = c.Request.ParseForm()
if err != nil {
return err
}
quotedValues(c.Request.PostForm, quotedfields)
c.Request.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(c.Request.PostForm.Encode())))
err = c.MustBindWith(data, binding.FormPost)
if err != nil {
return err
}
c.Request.Body = ioutil.NopCloser(bytes.NewBuffer(body))
return nil
}

@LaysDragon LaysDragon self-assigned this Oct 15, 2020
@LaysDragon LaysDragon added the enhancement New feature or request label Oct 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant