完成数据过主干逻辑,细节健壮性有待继续完善 #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 1cdf5449fd - Show all commits

View File

@ -275,3 +275,26 @@ func TestDataFilterDiffArr(t *testing.T) {
filter.Filter()
//fmt.Println()
}
// TestDataFilterRootArr ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 20:45 2023/8/31
func TestDataFilterRootArr(t *testing.T) {
source := []map[string]interface{}{
{"user_list": []interface{}{map[string]interface{}{"name": "alex", "age": 18, "number": 1}}},
{"user_list": []interface{}{map[string]interface{}{"name": "bob", "age": 28, "number": 2}}},
{"user_list": []interface{}{map[string]interface{}{"name": "andy", "age": 28, "number": 2}}},
}
rule := []*FilterDataRule{
// {SourceKey: "name", MapKey: "slice.[]", DefaultValue: "用户姓名默认值"},
{SourceKey: "[].user_list.[].name", MapKey: "user_list.[].detail.name", DefaultValue: "用户姓名默认值"},
{SourceKey: "[].user_list.[].age", MapKey: "user_list.[].detail.age", DefaultValue: "用户姓名默认值"},
}
byteData, _ := json.Marshal(source)
filter := NewDataFilter(string(byteData), rule)
filter.UserItemToSlice()
filter.Filter()
//fmt.Println()
}