Git Product home page Git Product logo

Comments (4)

yepher avatar yepher commented on June 19, 2024

Added a fix here:

Commit: 85d31e2 [85d31e2]
Parents: fe82e99
Author: Chris Wilson [email protected]
Date: February 11, 2016 at 9:23:22 AM CST
Labels: HEAD master

• Fixes problem where Timestamp was getting decoded as int64 instead of String.
• Changes imports to be relative so it is easier to test local changes or changes on a branch.

from gosparkpost.

VojtechVitek avatar VojtechVitek commented on June 19, 2024

#35 parses timestamps into native golang time.Time values via custom JSON Unmarshaller. I noticed that Webhook Event API returns Unix timestamps (int64) and Event Samples API returns string of RFC 3339-like format.

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
}

from gosparkpost.

VojtechVitek avatar VojtechVitek commented on June 19, 2024

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.

from gosparkpost.

VojtechVitek avatar VojtechVitek commented on June 19, 2024

@yepher this can be closed, since Timestamps are now time.Time values

from gosparkpost.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.