完成数据过主干逻辑,细节健壮性有待继续完善 #4
| @ -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 是否为数组路径 | ||||
|  | ||||
		Reference in New Issue
	
	Block a user