Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
support Source config
  • Loading branch information
prayansh committed Aug 27, 2019
commit 67871b0a7a562a0de2ec7065d2939732a7894df7
1 change: 1 addition & 0 deletions batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package objects
import "encoding/json"

type batch struct {
Source string `json:"source"`
Collection string `json:"collection"`
WriteKey string `json:"write_key"`
Objects json.RawMessage `json:"objects"`
Expand Down
10 changes: 10 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ const (

// Endpoint for Segment Objects API.
DefaultBaseEndpoint = "https://objects.segment.com"

// Default source
DefaultSource = "project"
)

var (
Expand All @@ -36,6 +39,8 @@ type Config struct {
Logger *log.Logger
Client *http.Client

Source string

MaxBatchBytes int
MaxBatchCount int
MaxBatchInterval time.Duration
Expand Down Expand Up @@ -89,6 +94,10 @@ func getFinalConfig(c Config) Config {
c.MaxBatchInterval = 10 * time.Second
}

if c.Source == "" {
c.Source = DefaultSource
}

return c
}

Expand All @@ -107,6 +116,7 @@ func (c *Client) flush(b *buffer) {
rm := b.marshalArray()
c.semaphore.Run(func() {
batchRequest := &batch{
Source: c.Source,
Collection: b.collection,
WriteKey: c.writeKey,
Objects: rm,
Expand Down
1 change: 1 addition & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func (c *ClientTestSuite) TestNewClient() {
c.NotNil(client.Logger)
c.NotNil(client.semaphore)
c.NotNil(client.wg)
c.NotNil(client.Source)
c.Equal("writeKey", client.writeKey)
c.Equal(0, client.cmap.Count())
}
Expand Down