Golang XML Unmarshal and time.Time fields

前端 未结 4 1812
南笙
南笙 2021-02-04 01:14

I have XML data I am retrieving via a REST API that I am unmarshal-ing into a GO struct. One of the fields is a date field, however the date format returned by the API does not

4条回答
  •  不要未来只要你来
    2021-02-04 01:49

    From what I have read the encoding/xml has some known issues that have been put off until a later date...

    To get around this issue, instead of using the type time.Time use string and handle the parsing afterwards.

    I had quite a bit of trouble getting time.Parse to work with dates in the following format: "Fri, 09 Aug 2013 19:39:39 GMT"

    Oddly enough I found that "net/http" has a ParseTime function that takes a string that worked perfectly... http://golang.org/pkg/net/http/#ParseTime

提交回复
热议问题