22 lines
389 B
Go
22 lines
389 B
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
)
|
|
|
|
type UnixTimestamp struct {
|
|
time.Time
|
|
}
|
|
|
|
func (ut *UnixTimestamp) UnmarshalJSON(b []byte) error {
|
|
var timestamp int64
|
|
// Unmarshal the raw JSON bytes into an int64
|
|
if err := json.Unmarshal(b, ×tamp); err != nil {
|
|
return err
|
|
}
|
|
// Convert the epoch seconds to a time.Time object
|
|
ut.Time = time.Unix(timestamp, 0)
|
|
return nil
|
|
}
|