refactor(coperator): 将 Filter 类型断言改为 map[string]interface{} 类型
- 修改了 DocumentOperator 和 FieldOperator 函数中的 Filter 类型断言 - 将其改为 map[string]interface{} 类型,以提高灵活性和兼容性 - 更新了相关测试文件中的 Filter 类型为 map[string]interface{}
This commit is contained in:
parent
3750e9ddd9
commit
0772d8e2fe
|
@ -97,7 +97,7 @@ func DocumentOperator(doc *Document, vfilter Filter, key string, value interface
|
|||
}
|
||||
continue
|
||||
}
|
||||
if f, ok := v.(Filter); ok {
|
||||
if f, ok := v.(map[string]interface{}); ok {
|
||||
ret, err = FieldOperator(doc, f, k, nil)
|
||||
if !ret {
|
||||
return ret, err
|
||||
|
@ -133,7 +133,7 @@ func FieldOperator(doc *Document, vfilter Filter, key string, value interface{})
|
|||
if !ok {
|
||||
return false, errors.New("unsupport operator")
|
||||
}
|
||||
if fv, ok := v.(Filter); ok {
|
||||
if fv, ok := v.(map[string]interface{}); ok {
|
||||
ret, err = opFn(doc, fv, key, nil)
|
||||
if !ret {
|
||||
return ret, err
|
||||
|
|
|
@ -105,7 +105,7 @@ func TestValueOperator(t *testing.T) {
|
|||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, _ := ValueOperator(&tt.doc, Filter{}, strings.Join(tt.path, "."), tt.value)
|
||||
got, _ := ValueOperator(&tt.doc, map[string]interface{}{}, strings.Join(tt.path, "."), tt.value)
|
||||
if got != tt.want {
|
||||
t.Errorf("Document.GetPathArray() = %v, want %v", got, tt.want)
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ func TestDocumentOperator(t *testing.T) {
|
|||
"id": 1,
|
||||
},
|
||||
},
|
||||
filter: Filter{
|
||||
filter: map[string]interface{}{
|
||||
"user.id": 1,
|
||||
},
|
||||
want: true,
|
||||
|
@ -137,8 +137,8 @@ func TestDocumentOperator(t *testing.T) {
|
|||
doc: Document{
|
||||
"age": 18,
|
||||
},
|
||||
filter: Filter{
|
||||
"age": Filter{
|
||||
filter: map[string]interface{}{
|
||||
"age": map[string]interface{}{
|
||||
"$gt": 17,
|
||||
},
|
||||
},
|
||||
|
@ -149,8 +149,8 @@ func TestDocumentOperator(t *testing.T) {
|
|||
doc: Document{
|
||||
"age": 18,
|
||||
},
|
||||
filter: Filter{
|
||||
"age": Filter{
|
||||
filter: map[string]interface{}{
|
||||
"age": map[string]interface{}{
|
||||
"$gt": 17,
|
||||
"$lt": 16,
|
||||
},
|
||||
|
@ -162,8 +162,8 @@ func TestDocumentOperator(t *testing.T) {
|
|||
doc: Document{
|
||||
"age": 18,
|
||||
},
|
||||
filter: Filter{
|
||||
"age": Filter{
|
||||
filter: map[string]interface{}{
|
||||
"age": map[string]interface{}{
|
||||
"$in": []interface{}{16, 17, 18},
|
||||
},
|
||||
},
|
||||
|
@ -174,8 +174,8 @@ func TestDocumentOperator(t *testing.T) {
|
|||
doc: Document{
|
||||
"age": 22,
|
||||
},
|
||||
filter: Filter{
|
||||
"age": Filter{
|
||||
filter: map[string]interface{}{
|
||||
"age": map[string]interface{}{
|
||||
"$nin": []interface{}{16, 17, 18},
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue