feature/upgrade_filter #7

Merged
zhangdeman merged 14 commits from feature/upgrade_filter into master 2024-12-02 14:35:30 +08:00
2 changed files with 60 additions and 1 deletions
Showing only changes of commit d25e579ecf - Show all commits

View File

@ -183,3 +183,62 @@ func ExpandArrayPath(jsonStr string, pathConfig string, mapConfig string, expend
}
return nil
}
// IsObject 判断是否是对象, 兼容序列化之后的对象
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:04 2024/12/1
func IsObject(gjsonResult gjson.Result) bool {
return gjsonResult.IsObject() || gjson.Parse(gjsonResult.String()).IsObject()
}
// IsArray 判断是否为数组
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:05 2024/12/1
func IsArray(gjsonResult gjson.Result) bool {
return gjsonResult.IsArray() || gjson.Parse(gjsonResult.String()).IsArray()
}
// Object 兼容序列化之后的对象
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:09 2024/12/1
func Object(gjsonResult gjson.Result) gjson.Result {
res := gjson.Parse(gjsonResult.String())
if res.IsObject() {
return res
}
return gjsonResult
}
// Array ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:09 2024/12/1
func Array(gjsonResult gjson.Result) gjson.Result {
res := gjson.Parse(gjsonResult.String())
if res.IsArray() {
return res
}
return gjsonResult
}
// Result ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:12 2024/12/1
func Result(gjsonResult gjson.Result) gjson.Result {
if IsObject(gjsonResult) {
return gjsonResult
}
if IsArray(gjsonResult) {
return Array(gjsonResult)
}
return gjsonResult
}

View File

@ -165,7 +165,7 @@ func TestExpandArrayPath(t *testing.T) {
}
byteData, _ := json.Marshal(mapData)
jsonStr := string(byteData)
// fmt.Println(jsonStr)
var pathExpendRes = &ExpendArrayResult{
PathList: nil,
PathMap: nil,