Skip to content
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

feat(payload): add user_id to payload #3

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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