完成数据过主干逻辑,细节健壮性有待继续完善 #4

Merged
zhangdeman merged 13 commits from feature/data_filter into master 2023-09-02 22:17:14 +08:00
Showing only changes of commit 2230411f76 - Show all commits

View File

@ -52,6 +52,7 @@ type FilterDataRule struct {
//
// Date : 2022/1/22 9:50 PM
func NewDataFilter(source string, filterRule []*FilterDataRule, filterOption *FilterOption) *DataFilter {
source = fmt.Sprintf(`{"%v":%v}`, virtualRoot, source)
if nil == filterOption {
filterOption = &FilterOption{}
}
@ -67,8 +68,8 @@ func NewDataFilter(source string, filterRule []*FilterDataRule, filterOption *Fi
}
// 去除末尾的 .[]
for _, item := range filterRule {
item.MapKey = strings.TrimRight(item.MapKey, ".[]")
item.SourceKey = strings.TrimRight(item.SourceKey, ".[]")
item.MapKey = virtualRoot + "." + strings.TrimRight(item.MapKey, ".[]")
item.SourceKey = virtualRoot + "." + strings.TrimRight(item.SourceKey, ".[]")
mapIsArr := df.isArrPath(item.MapKey)
if !mapIsArr {
df.filterRule = append(df.filterRule, item)
@ -146,7 +147,7 @@ func (df *DataFilter) Filter() (string, error) {
}
}
df.logPrint(logLevelDebug, "过滤结果", df.rewriteResult)
return df.rewriteResult, nil
return gjson.Get(df.rewriteResult, virtualRoot).String(), nil
}
// isArrPath 是否为数组路径