mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package pipeline
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/data"
|
|
)
|
|
|
|
// ConditionType represents multiple condition operator type.
|
|
type ConditionType string
|
|
|
|
const (
|
|
ConditionAll ConditionType = "all"
|
|
ConditionAny ConditionType = "any"
|
|
)
|
|
|
|
// MultipleConditionChecker can check multiple conditions according to ConditionType.
|
|
type MultipleConditionChecker struct {
|
|
ConditionType ConditionType
|
|
Conditions []ConditionChecker
|
|
}
|
|
|
|
const ConditionCheckerTypeMultiple = "multiple"
|
|
|
|
func (c *MultipleConditionChecker) Type() string {
|
|
return ConditionCheckerTypeMultiple
|
|
}
|
|
|
|
func (c *MultipleConditionChecker) CheckCondition(ctx context.Context, frame *data.Frame) (bool, error) {
|
|
for _, cond := range c.Conditions {
|
|
ok, err := cond.CheckCondition(ctx, frame)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
if ok && c.ConditionType == ConditionAny {
|
|
return true, nil
|
|
}
|
|
if !ok && c.ConditionType == ConditionAll {
|
|
return false, nil
|
|
}
|
|
}
|
|
if c.ConditionType == ConditionAny {
|
|
return false, nil
|
|
}
|
|
return true, nil
|
|
}
|
|
|
|
// NewMultipleConditionChecker creates new MultipleConditionChecker.
|
|
func NewMultipleConditionChecker(conditionType ConditionType, conditions ...ConditionChecker) *MultipleConditionChecker {
|
|
return &MultipleConditionChecker{ConditionType: conditionType, Conditions: conditions}
|
|
}
|