Skip to content

Commit

Permalink
dev: add multi extract exp support
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangxu19830126 committed Feb 8, 2018
1 parent 17fbe94 commit 7b93231
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/proxy/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,19 @@ func (rd *render) extract(src jsoniter.Any) map[string]interface{} {
}

func extractValue(attr *metapb.RenderAttr, src jsoniter.Any, obj map[string]interface{}) {
obj[attr.Name] = src.Get(getPaths(attr.ExtractExp)...).GetInterface()
exps := strings.Split(attr.ExtractExp, ",")

if len(exps) == 1 {
obj[attr.Name] = src.Get(getPaths(attr.ExtractExp)...).GetInterface()
return
}

sub := make(map[string]interface{})
obj[attr.Name] = sub
for _, exp := range exps {
paths := getPaths(exp)
sub[paths[len(paths)-1].(string)] = src.Get(paths...).GetInterface()
}
}

func getPaths(attr string) []interface{} {
Expand Down

0 comments on commit 7b93231

Please sign in to comment.