-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfigs.go
More file actions
117 lines (99 loc) · 4.58 KB
/
Copy pathconfigs.go
File metadata and controls
117 lines (99 loc) · 4.58 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package dtos
import "encoding/json"
// VariantDTO represents a variant (treatment) with its definition (directive for evaluator)
type VariantDTO struct {
Name string `json:"name"`
Definition interface{} `json:"definition"` // Acts as directive for the evaluator
}
// RawMatcherDTO represents a matcher as returned by the /configs endpoint (needs transformation)
type RawMatcherDTO struct {
Type string `json:"type"` // e.g., "WHITELIST", "IS_EQUAL_TO", "GREATER_THAN_OR_EQUAL_TO"
Attribute string `json:"attribute"` // Attribute name (optional for ALL_KEYS)
Data map[string]interface{} `json:"data"` // Flexible data structure
}
// RawPartitionDTO represents a partition as returned by the /configs endpoint
type RawPartitionDTO struct {
Variant string `json:"variant"` // Uses "variant" instead of "treatment"
Size int `json:"size"`
}
// RawConditionDTO represents a condition as returned by the /configs endpoint (needs transformation)
type RawConditionDTO struct {
Label string `json:"label"`
Partitions []RawPartitionDTO `json:"partitions"`
Matchers []RawMatcherDTO `json:"matchers"` // Flat array, not MatcherGroup
// Note: No ConditionType field in raw conditions
}
// TargetingDTO represents the targeting rules for a config
type TargetingDTO struct {
Default string `json:"default"` // The default variant name
Seed int64 `json:"seed"` // Seed for hashing
TrafficAllocation int `json:"trafficAllocation"` // Percentage of traffic allocated
TrafficAllocationSeed int64 `json:"trafficAllocationSeed"` // Seed for traffic allocation
Conditions []RawConditionDTO `json:"conditions"` // Raw targeting conditions (need transformation)
}
// ConfigDTO represents a configuration definition fetched from the /configs endpoint
type ConfigDTO struct {
Name string `json:"name"`
TrafficTypeName string `json:"trafficTypeName"`
ChangeNumber int64 `json:"changeNumber"`
Status string `json:"status"` // Defaults to "ACTIVE" if missing
Killed bool `json:"killed"` // Defaults to false if missing
Sets []string `json:"sets"` // Feature flag sets
Variants []VariantDTO `json:"variants"`
Targeting TargetingDTO `json:"targeting"`
}
// ConfigsResponseDTO represents the response from the /configs endpoint
type ConfigsResponseDTO struct {
Updated []ConfigDTO `json:"updated"` // List of updated configs
Since int64 `json:"since"` // Starting change number
Till int64 `json:"till"` // Ending change number
RBS []RuleBasedSegmentDTO `json:"rbs"` // Rule-based segments
}
// FFResponseConfigs implements FFResponse interface for configs endpoint responses
type FFResponseConfigs struct {
configsResponse ConfigsResponseDTO
}
// NewFFResponseConfigs creates a new FFResponseConfigs instance from JSON data
func NewFFResponseConfigs(data []byte) (FFResponse, error) {
var configsResponse ConfigsResponseDTO
err := json.Unmarshal(data, &configsResponse)
if err != nil {
return nil, err
}
return &FFResponseConfigs{
configsResponse: configsResponse,
}, nil
}
// NeedsAnotherFetch checks if another fetch is needed based on the since and till values
func (f *FFResponseConfigs) NeedsAnotherFetch() bool {
return f.configsResponse.Since == f.configsResponse.Till
}
// RuleBasedSegments returns the list of rule-based segments from the response
func (f *FFResponseConfigs) RuleBasedSegments() []RuleBasedSegmentDTO {
return f.configsResponse.RBS
}
// FeatureFlags returns the list of feature flags (splits) converted from configs
func (f *FFResponseConfigs) FeatureFlags() []SplitDTO {
splits := make([]SplitDTO, 0, len(f.configsResponse.Updated))
for _, config := range f.configsResponse.Updated {
splits = append(splits, ConvertConfigToSplit(config))
}
return splits
}
// FFTill returns the till value for feature flags
func (f *FFResponseConfigs) FFTill() int64 {
return f.configsResponse.Till
}
// RBTill returns the till value for rule-based segments
func (f *FFResponseConfigs) RBTill() int64 {
return f.configsResponse.Till
}
// FFSince returns the since value for feature flags
func (f *FFResponseConfigs) FFSince() int64 {
return f.configsResponse.Since
}
// RBSince returns the since value for rule-based segments
func (f *FFResponseConfigs) RBSince() int64 {
return f.configsResponse.Since
}
var _ FFResponse = (*FFResponseConfigs)(nil)