forked from segmentio/analytics-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
group.go
42 lines (35 loc) · 1.13 KB
/
group.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package analytics
import "time"
var _ Message = (*Group)(nil)
// This type represents object sent in a group call as described in
// https://segment.com/docs/libraries/http/#group
type Group struct {
// This field is exported for serialization purposes and shouldn't be set by
// the application, its value is always overwritten by the library.
Type string `json:"type,omitempty"`
MessageId string `json:"messageId,omitempty"`
AnonymousId string `json:"anonymousId,omitempty"`
UserId string `json:"userId,omitempty"`
GroupId string `json:"groupId"`
Timestamp time.Time `json:"timestamp,omitempty"`
Context *Context `json:"context,omitempty"`
Traits Traits `json:"traits,omitempty"`
Integrations Integrations `json:"integrations,omitempty"`
}
func (msg Group) Validate() error {
if len(msg.GroupId) == 0 {
return FieldError{
Type: "analytics.Group",
Name: "GroupId",
Value: msg.GroupId,
}
}
if len(msg.UserId) == 0 && len(msg.AnonymousId) == 0 {
return FieldError{
Type: "analytics.Group",
Name: "UserId",
Value: msg.UserId,
}
}
return nil
}