You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I use iris as a simple web server and found a problem in parameter binding. When I send two int64 parameters with Get method, the second parameter will not bind to my struct. This problem may not the regular of bug description but occurred when I debug and step into the variable.
To Reproduce
Steps to reproduce the behavior:
// 1. My struct is defined as:
type GTClip struct {
Id int64 `gorm:"column:id" json:"id"`
Clip string `gorm:"column:clip" json:"clip"`
Scene string `gorm:"column:scene" json:"scene"`
Path string `gorm:"column:path" json:"path"`
SetId int64 `gorm:"column:set_id" json:"set_id"`
Deleted int `gorm:"column:deleted" json:"-"`
}
// 2. the route and function implemented as:
gt := app.Party("/gt")
{
gt.Use(iris.Compression)
clip := gt.Party("/clip")
{
// ... other unrelated method
clip.Get("/list", func (ctx iris.Context) {
var (
gtClipReq = &model.GTClip{}
err error
)
if err := ctx.ReadBody(gtClip); err != nil { // step point 1
ctx.StopWithError(iris.StatusBadRequest, err)
return
}
if gtClip.SetId, err = ctx.URLParamInt64("set_id"); err != nil { // step point 2
ctx.StopWithError(iris.StatusBadRequest, err)
return
}
ctx.JSON(iris.Map{
"code": 0,
"err": nil,
})
})
}
}
launch server and send request: http://127.0.0.1:8080/gt/clip/list?id=11&set_id=12 Expected behavior
The struct GTClip menber of Id and SetId should be bind as 11 and 12 respectively, with above requests. But until called function "ctx.URLParamInt64("set_id")", the member SetId is not binded the expected value 12. As comment at "step point 1".
After calling the ctx.URLParamInt64("set_id"), SetId is set to 12. As comment at "step point 2".
Another experiment is that if I add a parameter scene, member of Scene will be correctly binded! eg: http://127.0.0.1:8080/gt/clip/list?id=11&set_id=11&scene=turn Screenshots
Desktop (please complete the following information):
OS: macOs 13.2 (22D49)
iris.Version
v12.2.8
Please make sure the bug is reproducible over the main branch:
YES, the version I updated is v12.2.11-0.20240122133509-ddda4f699854, still has same problem
Additional context
I think there might be some misunderstand when I use ctx.ReadBody method. In fact I can't remember such many parameter binding methods and always use ctx.ReadBody instead. Am I right?
The text was updated successfully, but these errors were encountered:
soarchorale
changed the title
[BUG] Can not bind parameter of struct using ReadBody
[Problem] Can not bind parameter of struct using ReadBody
Feb 29, 2024
soarchorale
changed the title
[Problem] Can not bind parameter of struct using ReadBody
[Question] Can not bind parameter of struct using ReadBody
Feb 29, 2024
Describe the bug
I use iris as a simple web server and found a problem in parameter binding. When I send two int64 parameters with Get method, the second parameter will not bind to my struct. This problem may not the regular of bug description but occurred when I debug and step into the variable.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The struct GTClip menber of Id and SetId should be bind as 11 and 12 respectively, with above requests. But until called function "ctx.URLParamInt64("set_id")", the member SetId is not binded the expected value 12. As comment at "step point 1".
After calling the ctx.URLParamInt64("set_id"), SetId is set to 12. As comment at "step point 2".
Another experiment is that if I add a parameter scene, member of Scene will be correctly binded! eg: http://127.0.0.1:8080/gt/clip/list?id=11&set_id=11&scene=turn
Screenshots
Desktop (please complete the following information):
iris.Version
Please make sure the bug is reproducible over the
main
branch:YES, the version I updated is v12.2.11-0.20240122133509-ddda4f699854, still has same problem
Additional context
I think there might be some misunderstand when I use ctx.ReadBody method. In fact I can't remember such many parameter binding methods and always use ctx.ReadBody instead. Am I right?
The text was updated successfully, but these errors were encountered: