映射非数组, 数据源数组处理
This commit is contained in:
@ -85,3 +85,58 @@ func TestDataFilter_getDataAsSlice(t *testing.T) {
|
||||
fmt.Println(df.getDataAsSlice(string(byteData), []string{"list", "age", "list_test", "a"}))
|
||||
fmt.Println(df.getDataAsSlice(string(byteData), []string{"list", "age", "list_test", "b"}))
|
||||
}
|
||||
|
||||
// TestDataFilter_sourceArrAndMapSingle map 非数组,数据源数组
|
||||
//
|
||||
// Author : zhangdeman001@ke.com<张德满>
|
||||
//
|
||||
// Date : 11:24 2023/9/2
|
||||
func TestDataFilter_sourceArrAndMapSingle(t *testing.T) {
|
||||
source := map[string]interface{}{
|
||||
"list": []interface{}{
|
||||
map[string]interface{}{
|
||||
"name": "1",
|
||||
"age": "2",
|
||||
"list_test": []interface{}{
|
||||
map[string]interface{}{
|
||||
"a": "a",
|
||||
"b": "b",
|
||||
"c": map[string]interface{}{
|
||||
"a": "1",
|
||||
},
|
||||
"d": []int{1, 2, 3},
|
||||
},
|
||||
},
|
||||
},
|
||||
map[string]interface{}{
|
||||
"name": "3",
|
||||
"age": "4",
|
||||
"list_test": []interface{}{
|
||||
map[string]interface{}{
|
||||
"a": "a1",
|
||||
"b": "b1",
|
||||
"c": map[string]interface{}{
|
||||
"a": "a",
|
||||
},
|
||||
"d": []int{1, 2, 3},
|
||||
},
|
||||
},
|
||||
},
|
||||
map[string]interface{}{
|
||||
"name": "5",
|
||||
"age": "6",
|
||||
},
|
||||
},
|
||||
}
|
||||
df := &DataFilter{
|
||||
source: serialize.JSON.MarshalForString(source),
|
||||
filterRule: []*FilterDataRule{
|
||||
{SourceKey: "list.[].list_test.[].a", MapKey: "a_list", DefaultValue: "[]", WithDefault: true},
|
||||
{SourceKey: "list.[].list_test.[].b", MapKey: "b_list", DefaultValue: "[]", WithDefault: true},
|
||||
{SourceKey: "list.[].list_test.[].c", MapKey: "c_list", DefaultValue: "[]", WithDefault: true},
|
||||
{SourceKey: "list.[].list_test.[].d", MapKey: "d_list", DefaultValue: "[]", WithDefault: true},
|
||||
},
|
||||
filterOption: &FilterOption{DebugModel: true},
|
||||
}
|
||||
fmt.Println(df.Filter())
|
||||
}
|
||||
|
Reference in New Issue
Block a user