-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathloop.go
46 lines (40 loc) · 1.22 KB
/
loop.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
package resolve
import (
"fmt"
"github.com/project-flogo/core/data"
"github.com/project-flogo/core/data/path"
)
var loopResolverInfo = NewImplicitResolverInfo(false, true)
type LoopResolver struct {
}
func (*LoopResolver) GetResolverInfo() *ResolverInfo {
return loopResolverInfo
}
// LoopResolver Loop Resolver $Loop[item]
func (*LoopResolver) Resolve(scope data.Scope, item string, field string) (interface{}, error) {
var value interface{}
var exist bool
if item == "" {
value, exist = scope.GetValue("_loop")
if !exist {
return nil, fmt.Errorf("failed to resolve current Loop: '%s', ensure that Loop is configured in the application", field)
}
} else if item == "index" {
//To access the index value eg: $Loop[index]
value, exist = scope.GetValue("_loop")
if !exist {
return nil, fmt.Errorf("failed to resolve current Loop: '%s', ensure that Loop is configured in the application", field)
}
return path.GetValue(value, ".index")
} else {
value, exist = scope.GetValue(item)
if !exist {
return nil, fmt.Errorf("failed to resolve Loop: '%s', ensure that Loop is configured in the application", item)
}
}
if field != "" {
return path.GetValue(value, "."+field)
} else {
return value, nil
}
}