package shared import ( "strconv" "time" ) // UnixTimestamp is a time.Time that can parse unix timestamps type UnixTimestamp time.Time // UnmarshalText implements encoding.TextUnmarshaler func (t *UnixTimestamp) UnmarshalText(b []byte) error { i, err := strconv.ParseInt(string(b), 10, 64) if err != nil { return err } *t = UnixTimestamp(time.Unix(i, 0)) return nil } // UnmarshalJSON implements json.Unmarshaler func (t *UnixTimestamp) UnmarshalJSON(b []byte) error { return t.UnmarshalText(b) } func (t UnixTimestamp) String() string { return time.Time(t).Format(`2006-01-02 15:04`) }