-
Notifications
You must be signed in to change notification settings - Fork 20
/
identify.go
64 lines (50 loc) · 1.42 KB
/
identify.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package posthog
import "time"
var _ Message = (*Identify)(nil)
// This type represents object sent in an identify call
type Identify 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
DistinctId string
Timestamp time.Time
Properties Properties
}
func (msg Identify) internal() {
panic(unimplementedError)
}
func (msg Identify) Validate() error {
if len(msg.DistinctId) == 0 {
return FieldError{
Type: "posthog.Identify",
Name: "DistinctId",
Value: msg.DistinctId,
}
}
return nil
}
type IdentifyInApi struct {
Type string `json:"type"`
Library string `json:"library"`
LibraryVersion string `json:"library_version"`
Timestamp time.Time `json:"timestamp"`
Event string `json:"event"`
DistinctId string `json:"distinct_id"`
Properties Properties `json:"properties"`
Set Properties `json:"$set"`
}
func (msg Identify) APIfy() APIMessage {
library := "posthog-go"
myProperties := Properties{}.Set("$lib", library).Set("$lib_version", getVersion())
apified := IdentifyInApi{
Type: msg.Type,
Event: "$identify",
Library: library,
LibraryVersion: getVersion(),
Timestamp: msg.Timestamp,
DistinctId: msg.DistinctId,
Properties: myProperties,
Set: msg.Properties,
}
return apified
}