From 7b932314e069eb851a3d03855a95271258eac982 Mon Sep 17 00:00:00 2001 From: "zhangxu19830126@gmail.com" Date: Thu, 8 Feb 2018 14:03:44 +0800 Subject: [PATCH] dev: add multi extract exp support --- pkg/proxy/render.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/proxy/render.go b/pkg/proxy/render.go index 8533bb54..20b70591 100644 --- a/pkg/proxy/render.go +++ b/pkg/proxy/render.go @@ -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{} {