How does the function BindQuery bind the array?
type DeleteQueryParam struct {
UserName int form:"name" binding:"required"
ttl string form:"ttl" binding:"required"
Id []int form:"id" binding:"required"
}
param id can't bind the array correctly

@younglifestyle please see #653 issue
BTW, you should search issue or pull request when answer question before. thanks!
Gin version: v1.4.0
OS: Linux
@thinkerou referenced both #653 and #570. Maybe I am doing something wrong, but there are no concrete examples anywhere.
Make a request with an array of form values will be parsed correctly as a list.
Request: https://www.example.com/publish?ids[]=16&ids[]=18&isPublished=true
Gin Backend:
func checkIfPublished(c *gin.Context) {
type queryHolder struct {
IsPublished bool `form:"isPublished" binding:"exists"`
Ids []uint `form:"ids[]" binding:"required"`
}
var qholder queryHolder
if err := c.ShouldBindQuery(&qholder); err != nil {
c.AbortWithStatus(http.StatusBadRequest)
return
}
log.Printf("%+v\n", qholder)
}
2019/10/20 16:09:34 {IsPublished:true Ids:[18]}
2019/10/20 16:09:34 {IsPublished:true Ids:[16,18]}
For me everything is ok:
2019/10/20 21:11:47 {IsPublished:true Ids:[16 18]}
[GIN] 2019/10/20 - 21:11:47 | 200 | 433.233碌s | ::1 | GET /hello?ids[]=16&ids[]=18&isPublished=true
curl -i "http://localhost:9000/hello?ids\[\]=16&ids\[\]=18&isPublished=true"
HTTP/1.1 200 OK
For me everything is ok:
2019/10/20 21:11:47 {IsPublished:true Ids:[16 18]} [GIN] 2019/10/20 - 21:11:47 | 200 | 433.233碌s | ::1 | GET /hello?ids[]=16&ids[]=18&isPublished=truecurl -i "http://localhost:9000/hello?ids\[\]=16&ids\[\]=18&isPublished=true" HTTP/1.1 200 OK
@vkd You were completely right so sorry about this. It was because I had my endpoint behind AWS gateway, which it does not support duplicates.