Skip to content

Commit

Permalink
Merge pull request #3 from openebs/add-userid
Browse files Browse the repository at this point in the history
feat(payload): add user_id to payload
  • Loading branch information
niladrih authored Nov 8, 2023
2 parents ccd6938 + a3c680f commit 2277f89
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func (c *MeasurementClient) Send(event *event.OpenebsEvent) error {
dataPayload, err := payload.NewPayload(
payload.WithClientId(client.clientId),
payload.WithOpenebsEvent(event),
payload.WithUserId(client.clientId),
)

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ func main() {
client, err := gaClient.NewMeasurementClient(
gaClient.WithApiSecret("NguBiGh6QeOdeG3zJswggQ"),
gaClient.WithMeasurementId("G-TZGP46618W"),
gaClient.WithClientId("uniqueUserId-000000001"),
gaClient.WithClientId("uniqueClientId-000000001"),
)
if err != nil {
panic(err)
Expand Down
12 changes: 12 additions & 0 deletions payload/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type PayloadOption func(*Payload) error
type Payload struct {
ClientId string `json:"client_id"`
Events []ApiEvent `json:"events"`
UserId string `json:"user_id"`
}

type ApiEvent struct {
Expand Down Expand Up @@ -43,6 +44,17 @@ func WithClientId(clientId string) PayloadOption {
}
}

func WithUserId(userId string) PayloadOption {
return func(p *Payload) error {
if len(userId) == 0 {
return errors.Errorf("failed to set Payload userId: id is an empty string")
}

p.UserId = userId
return nil
}
}

func WithOpenebsEvent(event *event.OpenebsEvent) PayloadOption {
return func(p *Payload) error {
p.Events = append(p.Events, ApiEvent{
Expand Down

0 comments on commit 2277f89

Please sign in to comment.