sjson #1

Merged
zhangdeman merged 7 commits from sjson into master 2023-02-06 11:44:09 +08:00
Showing only changes of commit 4ed5891065 - Show all commits

View File

@ -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<白茶清欢>