The easiest way is to use struct embedding so that your UnixTime can use the time.Time methods: https://play.golang.org/p/WltVTKxylT
On Sat, Nov 19, 2016 at 12:32 AM, Sathish VJ <sathis...@gmail.com> wrote: > That by itself works, but I still haven't figured out how to make a custom > marshal type work automatically in both directions. i.e. the streaming part > in json is in unix time format but internally it is time.Time. > > Can we put a custom type in the tag value? Something like this? > T time.Time `json:"created_time,Unixtime"` > > It doesn't work in my sample. And I've not found any samples on the net > yet. > New play link: https://play.golang.org/p/f_t0A9M5bL > > > On Saturday, 19 November 2016 12:32:35 UTC+5:30, Dave Cheney wrote: >> >> UnixTime and time.Time are different types with different method sets. >> UnixTime is not a subclass or a child type of time.Time as there is no such >> thing as inheritance in go. >> >> Try printing this value. >> >> time.Time(*t) >> >> Dave > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.