增加obj2slice,以及数据类型检测
This commit is contained in:
@ -206,3 +206,36 @@ func TestDataFilter(t *testing.T) {
|
||||
filter := NewDataFilter(string(byteData), rule)
|
||||
fmt.Println(filter.Filter())
|
||||
}
|
||||
|
||||
// TestDataFilterForObiToSlice ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2022/1/23 12:06 AM
|
||||
func TestDataFilterForObiToSlice(t *testing.T) {
|
||||
source := map[string]interface{}{
|
||||
"name": "zhangdeman",
|
||||
"age": 18,
|
||||
"height": 180,
|
||||
"extra": map[string]interface{}{
|
||||
"age": 18,
|
||||
"height": 180,
|
||||
"slice": []int{1, 2, 3},
|
||||
},
|
||||
"slice_data": []int{1, 2, 3},
|
||||
"map": map[string]interface{}{"a": 1, "b": 2, "c": 4},
|
||||
"table": []map[string]interface{}{
|
||||
{"name": "alex", "age": 18, "number": 1},
|
||||
{"name": "bob", "age": 28, "number": 2},
|
||||
{"name": "bob", "age": 28, "number": 2, "list": []int{1, 2, 3}},
|
||||
},
|
||||
}
|
||||
rule := []FilterDataRule{
|
||||
// {SourceKey: "name", MapKey: "slice.[]", DefaultValue: "用户姓名默认值"},
|
||||
{SourceKey: "age", MapKey: "slice.[]", DefaultValue: "用户姓名默认值"},
|
||||
{SourceKey: "height", MapKey: "slice.[]", DefaultValue: "用户姓名默认值"},
|
||||
}
|
||||
byteData, _ := json.Marshal(source)
|
||||
filter := NewDataFilter(string(byteData), rule)
|
||||
fmt.Println(filter.Filter())
|
||||
}
|
||||
|
Reference in New Issue
Block a user