mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2024-12-25 15:09:05 +01:00
Simplify EvalBoolCondition
This commit is contained in:
parent
a8821b7ac5
commit
2f0e229936
@ -283,8 +283,10 @@ func (c *metricAggregator) AddFunction(name string, function func(args ...interf
|
||||
}
|
||||
|
||||
func EvalBoolCondition(condition string, params map[string]interface{}) (bool, error) {
|
||||
newcond := strings.ReplaceAll(condition, "'", "\"")
|
||||
newcond = strings.ReplaceAll(newcond, "%", "\\")
|
||||
newcond :=
|
||||
strings.ReplaceAll(
|
||||
strings.ReplaceAll(
|
||||
condition, "'", "\""), "%", "\\")
|
||||
language := gval.NewLanguage(
|
||||
gval.Full(),
|
||||
metricCacheLanguage,
|
||||
@ -293,31 +295,21 @@ func EvalBoolCondition(condition string, params map[string]interface{}) (bool, e
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
var endResult bool = false
|
||||
endResult := false
|
||||
err = nil
|
||||
switch r := value.(type) {
|
||||
case bool:
|
||||
endResult = r
|
||||
case float64:
|
||||
if r != 0.0 {
|
||||
endResult = true
|
||||
}
|
||||
endResult = r != 0.0
|
||||
case float32:
|
||||
if r != 0.0 {
|
||||
endResult = true
|
||||
}
|
||||
endResult = r != 0.0
|
||||
case int:
|
||||
if r != 0 {
|
||||
endResult = true
|
||||
}
|
||||
endResult = r != 0
|
||||
case int64:
|
||||
if r != 0 {
|
||||
endResult = true
|
||||
}
|
||||
endResult = r != 0
|
||||
case int32:
|
||||
if r != 0 {
|
||||
endResult = true
|
||||
}
|
||||
endResult = r != 0
|
||||
default:
|
||||
err = fmt.Errorf("cannot evaluate '%s' to bool", newcond)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user