普通对象数据过滤
This commit is contained in:
41
tool/gabs_test.go
Normal file
41
tool/gabs_test.go
Normal file
@ -0,0 +1,41 @@
|
||||
// Package json_tool ...
|
||||
//
|
||||
// Description : json_tool ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2023-09-01 16:07
|
||||
package json_tool
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.zhangdeman.cn/zhangdeman/serialize"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestDataFilter_FilterNormalData 最基础对象
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 16:13 2023/9/1
|
||||
func TestDataFilter_FilterNormalData(t *testing.T) {
|
||||
source := map[string]interface{}{
|
||||
"name": "zhangdeman",
|
||||
"extra": map[string]interface{}{
|
||||
"age": 18,
|
||||
"height": 180,
|
||||
"slice": []int{1, 2, 3},
|
||||
},
|
||||
"slice": []int{1, 2, 3},
|
||||
}
|
||||
df := &DataFilter{
|
||||
source: serialize.JSON.MarshalForString(source),
|
||||
filterRule: []*FilterDataRule{
|
||||
{SourceKey: "name", MapKey: "user_name", DefaultValue: "油猴", WithDefault: true},
|
||||
{SourceKey: "extra.age", MapKey: "user_age", DefaultValue: "18", WithDefault: true},
|
||||
{SourceKey: "slice", MapKey: "user_index", DefaultValue: "[4,5,6]", WithDefault: true},
|
||||
{SourceKey: "none", MapKey: "none_default", DefaultValue: map[string]interface{}{"a": "a"}, WithDefault: true},
|
||||
},
|
||||
}
|
||||
fmt.Println(df.Filter())
|
||||
}
|
Reference in New Issue
Block a user