- With issues:
- Use the search tool before opening a new issue.
- Please provide source code and commit sha if you found a bug.
- Review existing issues and provide feedback or react to them.
Description
From the document example https://github.com/gin-gonic/gin/blob/master/docs/doc.md#bind-default-value-if-none-provided, can't run the correct result which is same as example.
How to reproduce
package main
import (
"net/http"
"github.com/gin-gonic/gin"
)
type Person struct {
Name string `form:"name,default=William"`
Age int `form:"age,default=10"`
Friends []string `form:"friends,default=Will;Bill"`
Addresses [2]string `form:"addresses,default=foo bar" collection_format:"ssv"`
LapTimes []int `form:"lap_times,default=1;2;3" collection_format:"csv"`
}
func main() {
g := gin.Default()
g.POST("/person", func(c *gin.Context) {
var req Person
if err := c.ShouldBindQuery(&req); err != nil {
c.JSON(http.StatusBadRequest, err)
return
}
c.JSON(http.StatusOK, req)
})
_ = g.Run("localhost:8080")
}
Expectations
$ curl -X POST http://localhost:8080/person
{"Name":"William","Age":10,"Friends":["Will","Bill"],"Colors":["red","blue"],"LapTimes":[1,2,3]}
Actual result
$ curl -X POST http://localhost:8080/person
{}
Environment
- go version: 1.23.2
- gin version (or commit ref): v1.10.0
- operating system: mac os 14.5
Comment From: kingcanfish
it is new feature after the gin version:v1.10.0, detail see https://github.com/gin-gonic/gin/pull/3986
if you want use it , maybe you need
go get github.com/gin-gonic/gin@master
use the master branch
Comment From: DachiChang
thx, I can get the right result when I upgraded to the master branch of gin.