-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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
binding issue with multipart form #398
Comments
Hello, type Form struct {
Token string `form:"token" binding:"required"`
Content string `form:"content" binding:"required"`
Info string `form:"info"`
Wait uint `form:"wait"`
}
// handler code
form := &Form{}
if c.Bind(&form) != nil {
// handling
}
|
@z0rr0 you pass pointer to pointer, but need just pointer: type Form struct {
Token string `form:"token" binding:"required"`
Content string `form:"content" binding:"required"`
Info string `form:"info"`
Wait uint `form:"wait"`
}
// handler code
form := &Form{}
if c.Bind(form) != nil {
// handling
} |
@mr-linch oh, thanks 😃 |
Hi gays ,I have a error like @TheInsideMan if I use map the error is: |
@littletwolee could you post your sample code to reproduce issue? |
@easonlin404 if modify the code from "c.Bind(&user)" to "c.Bind(user)" my struct is can you guys help me? Thx a lot |
@littletwolee gin are assuming the binding is using structs only, so you have to use package main
import (
"github.com/gin-gonic/gin"
)
type User struct {
ID int `json:"id" form:"id"`
Name string `json:"name" form:"name" binding:"required"`
Pwd string `json:"pwd" form:"pwd" binding:"required"`
}
var (
err error
id int
// user map[string]interface{} //you can't binding with map
)
func main() {
r := gin.New()
r.GET("/", func(c *gin.Context) {
var user User
err = c.Bind(&user)
if err != nil {
//...omitted
}
//...omitted
})
r.Run()
} |
thx @easonlin404, But I think this is a missing func. I need to have more rules with our fontend. It's very crazy.T.T |
@littletwolee What's your scenario? You want to dynamically binding with params? |
@easonlin404 Yep.I want get params is simply. Like map. I think request or form params were kv pairs. So, use map or struct were all good. |
@easonlin404 Mumm.I have a scenario. type user struct {
Name string
Pwd string
} Ok, Now I get a Http PUT request, It want to modify Name only.And I usr org package to control it.If I give orm a struct, it will change all fields. The param Pwd will be change from "xxx" to "".But I only to change Name. |
@TheInsideMan @littletwolee If you use form post map, please see #1387 , thanks a lot! |
#1749 merged! |
Hello Im getting the below error. This error has only started since switching to a multipart form with file being posted. Any advice much appreciated.
The text was updated successfully, but these errors were encountered: