kataras / iris

The fastest HTTP/2 Go Web Framework. New, modern and easy to learn. Fast development with Code you control. Unbeatable cost-performance ratio :rocket:
https://www.iris-go.com
BSD 3-Clause "New" or "Revised" License
25.29k stars 2.47k forks source link

How to set the default time format for serialization of MVC response objects? #2454

Open anden007 opened 6 months ago

anden007 commented 6 months ago

How should I set up MVC What is the format of the date and time when serializing objects in Response? ` func (this *BussApiController) GetActivityBySearch() mvc.Result {

  ActivityList,total := loadFromDB(...)
  return mvc.Response{
        Object: iris.Map{"success": success, "message": message, "activityList": ActivityList, "total": total},
  }

} ` I used to be able to set the default time format for JSON serialization using the GitHub. com/liamylian/jsontime/v2/v2 package when using v12.2.8. However, after upgrading to v12.2.11, this method has become ineffective.

`import(

  ...
  jsonTime "github.com/liamylian/jsontime/v2/v2"

) func main() {

  jsonTime.SetDefaultTimeFormat("2006-01-02 15:04:05", time.Local)
  ...

} `

anden007 commented 6 months ago

I seted app.Run(...,iris.WithTimeFormat("2006-01-02 15:04:05")) but it's not work.

anden007 commented 6 months ago

image I have found the reason. The default serialization function now uses the encoding/JSON package, which used to be a JSONiter. This can explain why I am unable to use the jsonTime ' Set Default Time Format ("2006-01-02 15:04:05", time. Local) to set the default time format.