-
Notifications
You must be signed in to change notification settings - Fork 18
/
alias.go
79 lines (64 loc) · 1.62 KB
/
alias.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package posthog
import "time"
var _ Message = (*Alias)(nil)
// This type represents object sent in a alias call
type Alias 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
Alias string
DistinctId string
Timestamp time.Time
}
func (msg Alias) internal() {
panic(unimplementedError)
}
func (msg Alias) Validate() error {
if len(msg.DistinctId) == 0 {
return FieldError{
Type: "posthog.Alias",
Name: "DistinctId",
Value: msg.DistinctId,
}
}
if len(msg.Alias) == 0 {
return FieldError{
Type: "posthog.Alias",
Name: "Alias",
Value: msg.Alias,
}
}
return nil
}
type AliasInApiProperties struct {
DistinctId string `json:"distinct_id"`
Alias string `json:"alias"`
Lib string `json:"$lib"`
LibVersion string `json:"$lib_version"`
}
type AliasInApi struct {
Type string `json:"type"`
Library string `json:"library"`
LibraryVersion string `json:"library_version"`
Timestamp time.Time `json:"timestamp"`
Properties AliasInApiProperties `json:"properties"`
Event string `json:"event"`
}
func (msg Alias) APIfy() APIMessage {
library := "posthog-go"
libraryVersion := getVersion()
apified := AliasInApi{
Type: msg.Type,
Event: "$create_alias",
Library: library,
LibraryVersion: libraryVersion,
Timestamp: msg.Timestamp,
Properties: AliasInApiProperties{
DistinctId: msg.DistinctId,
Alias: msg.Alias,
Lib: library,
LibVersion: libraryVersion,
},
}
return apified
}