-
-
Notifications
You must be signed in to change notification settings - Fork 77
/
condition_and.go
52 lines (46 loc) · 1.22 KB
/
condition_and.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package classifier
const andName = "and"
type andCondition struct{}
func (andCondition) name() string {
return andName
}
var andConditionPayloadSpec = payloadSingleKeyValue[[]any]{
key: andName,
valueSpec: payloadMustSucceed[[]any]{payloadList[any]{
itemSpec: payloadGeneric[any]{
jsonSchema: map[string]any{
"$ref": "#/definitions/condition",
},
},
description: "A condition that is satisfied if all conditions in a list are satisfied",
}},
}
func (andCondition) compileCondition(ctx compilerContext) (condition, error) {
payload, err := andConditionPayloadSpec.Unmarshal(ctx)
if err != nil {
return condition{}, ctx.error(err)
}
conds := make([]condition, len(payload))
for i, rawCond := range payload {
cond, err := ctx.compileCondition(ctx.child(numericPathPart(i), rawCond))
if err != nil {
return condition{}, ctx.fatal(err)
}
conds[i] = cond
}
return condition{
check: func(ctx executionContext) (bool, error) {
for _, c := range conds {
if result, err := c.check(ctx); err != nil {
return false, err
} else if !result {
return false, nil
}
}
return true, nil
},
}, nil
}
func (andCondition) JsonSchema() JsonSchema {
return andConditionPayloadSpec.JsonSchema()
}