• 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

Hi,

I has an issue with function func (formBinding) Bind(req *http.Request, obj interface{}) error {, when i push an query like http://0.0.0.0:8080/v1/transaction?start_date=2006-01-02T15:04:05+07:00&end_date=2006-01-02T15:04:05+07:00&page=1&page_size=100 and use if err := c.ShouldBindQuery(&request); err != nil { for parsing, but I see that the value in setTimeField(val string, structField reflect.StructField, value reflect.Value) error has invalid string, below is my debug

request url Gin Missing + character when binding form request

value in parse Gin Missing + character when binding form request

that you see the variable val is missing + character so it will be fail set time.

How to reproduce

define struct with time format

type A struct {
    StartDate *time.Time `form:"start_date" time_format:"2006-01-02T15:04:05Z07:00"`
    EndDate   *time.Time `form:"end_date" time_format:"2006-01-02T15:04:05Z07:00"`
}

binding a struct with gin context

var request dtos.SearchCodeTransactionRequest if err := c.ShouldBindQuery(&request); err != nil {`

see value in func setTimeField(val string, structField reflect.StructField, value reflect.Value) error { in form_mapping.go

Environment

  • go version: go version go1.15.6 linux/amd64
  • gin version (or commit ref): github.com/gin-gonic/gin v1.6.3
  • operating system: Ubuntu 20.04.1 LTS x86_64

Edit : I saw that gin will be unescape character + in query request, so how can we parse time with timezone like +07:00 ?

Comment From: neroswords

how to if i pass "1+2+3+4" as string not datetime format ?

Comment From: rq-s

这是来自QQ邮箱的假期自动回复邮件。 您好,我暂时我发立刻回复,我会尽快给您回复。