@@ -20,28 +20,29 @@ import (
20
20
)
21
21
22
22
type removingWalker struct {
23
- value * value.Value
23
+ value value.Value
24
+ out interface {}
24
25
schema * schema.Schema
25
26
toRemove * fieldpath.Set
26
27
}
27
28
28
- func removeItemsWithSchema (value * value.Value , toRemove * fieldpath.Set , schema * schema.Schema , typeRef schema.TypeRef ) {
29
+ func removeItemsWithSchema (val value.Value , toRemove * fieldpath.Set , schema * schema.Schema , typeRef schema.TypeRef ) value. Value {
29
30
w := & removingWalker {
30
- value : value ,
31
+ value : val ,
31
32
schema : schema ,
32
33
toRemove : toRemove ,
33
34
}
34
- resolveSchema (schema , typeRef , value , w )
35
+ resolveSchema (schema , typeRef , & val , w )
36
+ return value.ValueInterface {Value : w .out }
35
37
}
36
38
37
- // doLeaf should be called on leaves before descending into children, if there
38
- // will be a descent. It modifies w.inLeaf.
39
- func (w * removingWalker ) doLeaf () ValidationErrors { return nil }
40
-
41
- func (w * removingWalker ) doScalar (t * schema.Scalar ) ValidationErrors { return nil }
39
+ func (w * removingWalker ) doScalar (t * schema.Scalar ) ValidationErrors {
40
+ w .out = w .value .Interface ()
41
+ return nil
42
+ }
42
43
43
44
func (w * removingWalker ) doList (t * schema.List ) (errs ValidationErrors ) {
44
- l := ( * w .value ) .List ()
45
+ l := w .value .List ()
45
46
46
47
// If list is null, empty, or atomic just return
47
48
if l == nil || l .Length () == 0 || t .ElementRelationship == schema .Atomic {
@@ -58,23 +59,18 @@ func (w *removingWalker) doList(t *schema.List) (errs ValidationErrors) {
58
59
continue
59
60
}
60
61
if subset := w .toRemove .WithPrefix (pe ); ! subset .Empty () {
61
- val := value .Value (item )
62
- removeItemsWithSchema (& val , subset , w .schema , t .ElementType )
63
- item = val
64
-
62
+ item = removeItemsWithSchema (item , subset , w .schema , t .ElementType )
65
63
}
66
- newItems = append (newItems , item )
64
+ newItems = append (newItems , item . Interface () )
67
65
}
68
66
if len (newItems ) > 0 {
69
- * w .value = value .Value (value.ValueInterface {Value : newItems })
70
- } else {
71
- * w .value = nil
67
+ w .out = newItems
72
68
}
73
69
return nil
74
70
}
75
71
76
72
func (w * removingWalker ) doMap (t * schema.Map ) ValidationErrors {
77
- m := ( * w .value ) .Map ()
73
+ m := w .value .Map ()
78
74
79
75
// If map is null, empty, or atomic just return
80
76
if m == nil || m .Length () == 0 || t .ElementRelationship == schema .Atomic {
@@ -99,15 +95,13 @@ func (w *removingWalker) doMap(t *schema.Map) ValidationErrors {
99
95
}
100
96
}
101
97
if subset := w .toRemove .WithPrefix (pe ); ! subset .Empty () {
102
- removeItemsWithSchema (& val , subset , w .schema , fieldType )
98
+ val = removeItemsWithSchema (val , subset , w .schema , fieldType )
103
99
}
104
- newMap [k ] = val
100
+ newMap [k ] = val . Interface ()
105
101
return true
106
102
})
107
103
if len (newMap ) > 0 {
108
- * w .value = value .Value (value.ValueInterface {Value : newMap })
109
- } else {
110
- * w .value = nil
104
+ w .out = newMap
111
105
}
112
106
return nil
113
107
}
0 commit comments