From 4ed58910654770c5d838002aff2139e4fa34c42e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sun, 1 Jan 2023 19:28:20 +0800 Subject: [PATCH] save code --- filter.go | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/filter.go b/filter.go index d3d8541..790694c 100644 --- a/filter.go +++ b/filter.go @@ -54,8 +54,11 @@ func (f *filter) Deal() error { ) for _, rule := range f.filterRuleList { - if strings.Contains(rule.SourcePath, "[]") { + if f.IsArray(rule) { // 对于list的处理 + if err = f.handleArray(rule); nil != err { + return err + } continue } sourceResult := gjson.Get(f.sourceData, rule.SourcePath) @@ -79,6 +82,45 @@ func (f *filter) Deal() error { return nil } +// IsArray 判断是否为数组 +// +// Author : zhangdeman001@ke.com<张德满> +// +// Date : 17:48 2023/1/1 +func (f *filter) IsArray(rule MapRule) bool { + return strings.Contains(rule.SourcePath, "[]") +} + +// handleArray 处理数组(最复杂的场景) +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 17:41 2023/1/1 +func (f *filter) handleArray(rule MapRule) error { + sourcePathArray := strings.Split(rule.SourcePath, "[]") + mapPathArray := strings.Split(rule.MapPath, "[]") + if len(sourcePathArray) != len(mapPathArray) { + if len(mapPathArray) != 1 { + return errors.New("map rule is invalid") + } + // 提取某一个list下的字段, 组成一个list + + return nil + } + return nil +} + +// getAllFinalData ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 18:42 2023/1/1 +func (f *filter) getAllFinalData(pathArr []string) []string { + res := make([]string, 0) + + return res +} + // String 获取格式化之后的字符串 // // Author : go_developer@163.com<白茶清欢>