We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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 query parameter to time.Time field,when query parameter is a zero value, ShouldBind returns error.
time.Time
ShouldBind
package main import ( "github.com/gin-gonic/gin" ) func main() { g := gin.Default() g.GET("/", func(c *gin.Context) { var req struct { CreatedAt time.Time `form:"created_at" time_format:"unix"` } if err := c.ShouldBind(&req); err != nil { str := fmt.Sprintf("\n======err:%v\n", err) c.String(200, str) return } c.String(200, req.CreatedAt.String()) }) g.Run(":9000") }
$ curl "http://localhost:9000/?created_at=" 1970-01-01 08:00:00 +0800 CST
$ curl "http://localhost:9000/?created_at=" ======err:strconv.ParseInt: parsing "": invalid syntax 0001-01-01 00:00:00 +0000 UTC
I think these lines of code should move up to function start
gin/binding/form_mapping.go
Lines 417 to 420 in e46bd52
The text was updated successfully, but these errors were encountered:
fix: binding time with empty value (gin-gonic#4098)
67a65f1
Successfully merging a pull request may close this issue.
Description
Binding query parameter to
time.Time
field,when query parameter is a zero value,ShouldBind
returns error.How to reproduce
Expectations
Actual result
Environment
I think these lines of code should move up to function start
gin/binding/form_mapping.go
Lines 417 to 420 in e46bd52
The text was updated successfully, but these errors were encountered: