'golang fiber bodyparser to parse Time
in my project I am using fiber bodyparser to parse json received by my endpoint. I can parse ints and strings, but what if I need to parse Time? Consider the following code:
app.Post("/post", func(c *fiber.Ctx) error {
payload := struct {
Name string `json:"name"`
Email string `json:"email"`
StartedAt time.Time `json:"startedAt"` //<==== error here
ExpireAt time.Time `json:"expireAt"`
}{}
if err := c.BodyParser(&payload); err != nil {
return err
}
return c.JSON(payload)
}
I am receiving a string in 01.01.2001 12:00 format, but getting the following error:
json: cannot unmarshal \"\\\"01.01.2001 00:00\\\",\\\"expireAt\\\":\\\"0...\" into Go struct field requests.Campaign.startedAt of type time.Time"
Solution 1:[1]
Seems that Date should be passed in ISO string format (.toISOString() in js or something). It would be good if it were mentioned in official docs somehow.
Thank you.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jack |
