Provides support for evaluating string expressions.
You need to have 3 arguments to evaluate your expression.
- The string expression that defines the actual values and comparators against which the evaluation will happen
platform=='android'&&version>='10.9.8'&&segment==89
- The map of interface that defines the expression variables that you want to evaluate
{ "platform": "android", "version": "12.3.4", "segment": 98 }
- The final part is a list of
Variable
struct which defines the type of the variable in the expression.-
variable1 := Variable{ Name: "appVersion", Type: Version, Value: "10.9.7", } variable2 := Variable{ Name: "platform", Type: String, Value: "android", } var variables []Variable variables = append(variables, variable1) variables = append(variables, variable2)
-
- The final part is a list of
We will use all this to call the EvaluateExpression
which returns a *bool
and error
variable1 := Variable{
Name: "appVersion",
Type: Version,
Value: "10.9.7",
}
variable2 := Variable{
Name: "platform",
Type: String,
Value: "android",
}
variable3 := Variable{
Name: "segment",
Type: Number,
Value: 98,
}
var variables []Variable
variables = append(variables, variable1)
variables = append(variables, variable2)
request := map[string]interface{}{
"appVersion": "10.9.8",
}
result, err := EvaluateExpression("appVersion>='10.9.8'&&segment==98&&platform=='android'", request, variables)