-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timestamp is being decoded as int64
instead of string
#29
Comments
Added a fix here: Commit: 85d31e2 [85d31e2] • Fixes problem where Timestamp was getting decoded as |
#35 parses timestamps into native golang Snippet: type Timestamp time.Time
func (t *Timestamp) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprint(time.Time(*t).Unix())), nil
}
func (t *Timestamp) UnmarshalJSON(data []byte) error {
// Timestamps coming from Webhook Events are Unix timestamps.
unix, err := strconv.ParseInt(string(data), 10, 64)
if err == nil {
*t = Timestamp(time.Unix(unix, 0))
return nil
}
// Timestamps coming from Event Samples are in this RFC 3339-like format.
customTime, err := time.Parse("\"2006-01-02T15:04:05.000-07:00\"", string(data))
if err != nil {
return err
}
*t = Timestamp(customTime)
return nil
} |
Seems like the API changed or something in the last few days -- and instead of pure Unix timestamp integers, the Webhook API now returns strings. I had to add another commit https://github.com/pressly/gosparkpost/commit/c848d16a4f77aec77fb6e89d5fffd94441632a1a to trim the quotes. |
@yepher this can be closed, since Timestamps are now |
events/events.go implementation is based on an error in SparkPost documentation. The
Timestamp
field is being decoded asint64
instead ofString
.The text was updated successfully, but these errors were encountered: