Skip to content

Commit ea2d126

Browse files
author
Dave Johnston
committed
[FFM-1355]: The golang SDK was not evaluating custom rules for segments added directly to the flag
What: If a segment is added to the flag directly (as opposed to using the segmentMatch operator) then we call segment.Evaluate() This will check if the target is included, excluded or added via custom rules. Why: Previously we only checked in the target was included in a segment, it meant custom rules were being ignored.T
1 parent 073717e commit ea2d126

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

evaluation/feature.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,20 @@ type Clauses []Clause
8585
func (c Clauses) Evaluate(target *Target, segments Segments) bool {
8686
// AND operation
8787
for _, clause := range c {
88-
// operator should be evaluated based on type of attribute
89-
op, err := target.GetOperator(clause.Attribute)
90-
if err != nil {
91-
log.Warn(err)
88+
89+
// If this is a SegmentMatch clause, then we don't need to get the operator for the
90+
// attribute, as it is handled inside the Evaluate code below.
91+
//
92+
// If it is any other type of clause (i.e. if its an equals, contains etc)
93+
// then we need to get the appropriate operator depending on the type of attribute
94+
var op types.ValueType
95+
var err error
96+
97+
if clause.Op != segmentMatchOperator {
98+
op, err = target.GetOperator(clause.Attribute)
99+
if err != nil {
100+
log.Warn(err)
101+
}
92102
}
93103
if !clause.Evaluate(target, segments, op) {
94104
return false
@@ -239,12 +249,8 @@ func (fc FeatureConfig) GetVariationName(target *Target) string {
239249
if !ok {
240250
log.Error("The segment in variation map is invalid")
241251
} else {
242-
if segment.Included != nil {
243-
for _, t := range segment.Included {
244-
if t == target.Identifier {
245-
return variationMap.Variation
246-
}
247-
}
252+
if segment.Evaluate(target) {
253+
return variationMap.Variation
248254
}
249255
}
250256
}

0 commit comments

Comments
 (0)