Expressions: Use enumerations rather than strings (#83741)

This commit is contained in:
Ryan McKinley
2024-03-01 19:38:32 +02:00
committed by GitHub
parent c59ebfc60f
commit 5f6bf93dd5
9 changed files with 77 additions and 41 deletions
+12 -3
View File
@@ -54,7 +54,7 @@ type condition struct {
// Operator is the logical operator to use when there are two conditions in ConditionsCmd.
// If there are more than two conditions in ConditionsCmd then operator is used to compare
// the outcome of this condition with that of the condition before it.
Operator string
Operator ConditionOperatorType
}
// NeedsVars returns the variable names (refIds) that are dependencies
@@ -216,7 +216,7 @@ func (cmd *ConditionsCmd) executeCond(_ context.Context, _ time.Time, cond condi
return isCondFiring, isCondNoData, matches, nil
}
func compareWithOperator(b1, b2 bool, operator string) bool {
func compareWithOperator(b1, b2 bool, operator ConditionOperatorType) bool {
if operator == "or" {
return b1 || b2
} else {
@@ -262,8 +262,17 @@ type ConditionEvalJSON struct {
Type string `json:"type"` // e.g. "gt"
}
// The reducer function
// +enum
type ConditionOperatorType string
const (
ConditionOperatorAnd ConditionOperatorType = "and"
ConditionOperatorOr ConditionOperatorType = "or"
)
type ConditionOperatorJSON struct {
Type string `json:"type"`
Type ConditionOperatorType `json:"type"`
}
type ConditionQueryJSON struct {