forked from PostHog/posthog-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
feature_flag_config.go
84 lines (71 loc) · 1.63 KB
/
feature_flag_config.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
80
81
82
83
84
package posthog
type FeatureFlagPayload struct {
Key string
DistinctId string
Groups Groups
PersonProperties Properties
GroupProperties map[string]Properties
OnlyEvaluateLocally bool
SendFeatureFlagEvents *bool
}
func (c *FeatureFlagPayload) validate() error {
if len(c.Key) == 0 {
return ConfigError{
Reason: "Feature Flag Key required",
Field: "Key",
Value: c.Key,
}
}
if len(c.DistinctId) == 0 {
return ConfigError{
Reason: "DistinctId required",
Field: "Distinct Id",
Value: c.DistinctId,
}
}
if c.Groups == nil {
c.Groups = Groups{}
}
if c.PersonProperties == nil {
c.PersonProperties = NewProperties()
}
if c.GroupProperties == nil {
c.GroupProperties = map[string]Properties{}
}
if c.SendFeatureFlagEvents == nil {
tempTrue := true
c.SendFeatureFlagEvents = &tempTrue
}
return nil
}
type FeatureFlagPayloadNoKey struct {
DistinctId string
Groups Groups
PersonProperties Properties
GroupProperties map[string]Properties
OnlyEvaluateLocally bool
SendFeatureFlagEvents *bool
}
func (c *FeatureFlagPayloadNoKey) validate() error {
if len(c.DistinctId) == 0 {
return ConfigError{
Reason: "DistinctId required",
Field: "Distinct Id",
Value: c.DistinctId,
}
}
if c.Groups == nil {
c.Groups = Groups{}
}
if c.PersonProperties == nil {
c.PersonProperties = NewProperties()
}
if c.GroupProperties == nil {
c.GroupProperties = map[string]Properties{}
}
if c.SendFeatureFlagEvents == nil {
tempTrue := true
c.SendFeatureFlagEvents = &tempTrue
}
return nil
}