Skip to content

Commit

Permalink
Merge pull request #11 from FindHotel/context-fix
Browse files Browse the repository at this point in the history
Returning context nesting
  • Loading branch information
pzartem authored Nov 13, 2020
2 parents 9b4c2c7 + f30cb97 commit 4300fec
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions analytics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ func ExampleTrackObjLess() {
// "platform": "osx",
// "version": "1.1.0"
// },
// "timestamp": 0,
// "type": "track"
// }
// ],
Expand Down
5 changes: 4 additions & 1 deletion s3client.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,10 @@ func (c *s3Client) setTagsIfExsist(m Message) {

func (c *s3Client) encodeMessage(bw *bufferedEncoder, m Message) (ready bool, err error) {
if c.config.S3.UnwrappedMessage {
return bw.Push(m)
type unwrappedMessage struct {
Event Message `json:"event"`
}
return bw.Push(unwrappedMessage{Event: m})
}

ts := c.now()
Expand Down
2 changes: 1 addition & 1 deletion s3client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestTargetMessageMarshalling(t *testing.T) {
_, err = client.encodeMessage(encoder, m)
require.NoError(t, err)

expected = `{"userId":"tuna","event":"FooBared","timestamp":0,"properties":{"index":1,"qwer":3424}}` + "\n"
expected = `{"event":{"userId":"tuna","event":"FooBared","timestamp":0,"properties":{"index":1,"qwer":3424}}}` + "\n"
assertBuffer(t, encoder, expected)
}

Expand Down
10 changes: 5 additions & 5 deletions time.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package analytics

import (
"encoding/json"
"strconv"
"time"
)
Expand All @@ -11,11 +10,12 @@ type Time time.Time

// MarshalJSON marshals time as unix milliseconds.
func (t Time) MarshalJSON() ([]byte, error) {
if t == Time(time.Time{}) {
return json.Marshal(0)
var ts int64
if t != Time(time.Time{}) {
ts = time.Time(t).UnixNano() / int64(time.Millisecond)
}
millis := int64(time.Millisecond / time.Nanosecond)
return json.Marshal(time.Time(t).UnixNano() / millis)

return strconv.AppendInt(nil, ts, 10), nil
}

// UnmarshalJSON unmarshals milliseconds into Time.
Expand Down
1 change: 0 additions & 1 deletion track.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ type TrackObjLess struct {
// This field is exported for serialization purposes and shouldn't be set by
// the application, its value is always overwritten by the library.
Track
Timestamp *Time `json:"timestamp,omitempty"`
Properties interface{} `json:"properties,omitempty"`
}

Expand Down

0 comments on commit 4300fec

Please sign in to comment.