I use gin context to get json data and convert it into struct, it works fine. But what I have issues with is using time.Time as one of the field types:
type User struct {
CreatedAt time.Time `json:"created_at"`
}
In gin I use ShouldBind:
var user User
if err := c.ShouldBind(&user); err != nil {
c.JSON(200, g.H{})
return
}
The error I get is:
parsing time "2019-01-01T00:00:00" as "2006-01-02T15:04:05Z07:00": cannot parse "" as "Z07:00"
It seems that timezone segment is required. I also gave Z00:00 but again parse error raised.
How I can get datetime like "2022-01-01 20:00:00" and convert it into time.Time in Go or even with timezone?