Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality to access index value while iterating over primitive array #291

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion data/resolve/loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (*LoopResolver) GetResolverInfo() *ResolverInfo {
return loopResolverInfo
}

//LoopResolver Loop Resolver $Loop[item]
// LoopResolver Loop Resolver $Loop[item]
func (*LoopResolver) Resolve(scope data.Scope, item string, field string) (interface{}, error) {
var value interface{}
var exist bool
Expand All @@ -25,6 +25,13 @@ func (*LoopResolver) Resolve(scope data.Scope, item string, field string) (inter
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 {
Expand Down