@@ -18,7 +18,7 @@ func Fetch(from, i interface{}) interface{} {
18
18
// Methods can be defined on any type.
19
19
if v .NumMethod () > 0 {
20
20
method := v .MethodByName (i .(string ))
21
- if method .IsValid () && method . CanInterface () {
21
+ if method .IsValid () {
22
22
return method .Interface ()
23
23
}
24
24
}
@@ -35,16 +35,14 @@ func Fetch(from, i interface{}) interface{} {
35
35
36
36
case reflect .Array , reflect .Slice , reflect .String :
37
37
value := v .Index (ToInt (i ))
38
- if value .IsValid () && value . CanInterface () {
38
+ if value .IsValid () {
39
39
return value .Interface ()
40
40
}
41
41
42
42
case reflect .Map :
43
43
value := v .MapIndex (reflect .ValueOf (i ))
44
44
if value .IsValid () {
45
- if value .CanInterface () {
46
- return value .Interface ()
47
- }
45
+ return value .Interface ()
48
46
} else {
49
47
elem := reflect .TypeOf (from ).Elem ()
50
48
return reflect .Zero (elem ).Interface ()
@@ -59,7 +57,7 @@ func Fetch(from, i interface{}) interface{} {
59
57
}
60
58
return name == fieldName
61
59
})
62
- if value .IsValid () && value . CanInterface () {
60
+ if value .IsValid () {
63
61
return value .Interface ()
64
62
}
65
63
}
@@ -87,7 +85,7 @@ func FetchField(from interface{}, field *Field) interface{} {
87
85
// v.FieldByIndex() function as we don't need to verify what a field
88
86
// is a struct as we already did it on compilation step.
89
87
value := fieldByIndex (v , field .Index )
90
- if value .IsValid () && value . CanInterface () {
88
+ if value .IsValid () {
91
89
return value .Interface ()
92
90
}
93
91
}
@@ -124,7 +122,7 @@ func FetchMethod(from interface{}, method *Method) interface{} {
124
122
if kind != reflect .Invalid {
125
123
// Methods can be defined on any type, no need to dereference.
126
124
method := v .Method (method .Index )
127
- if method .IsValid () && method . CanInterface () {
125
+ if method .IsValid () {
128
126
return method .Interface ()
129
127
}
130
128
}
@@ -157,7 +155,7 @@ func Deref(i interface{}) interface{} {
157
155
}
158
156
}
159
157
160
- if v .IsValid () && v . CanInterface () {
158
+ if v .IsValid () {
161
159
return v .Interface ()
162
160
}
163
161
@@ -180,13 +178,13 @@ func Slice(array, from, to interface{}) interface{} {
180
178
}
181
179
182
180
value := v .Slice (a , b )
183
- if value .IsValid () && value . CanInterface () {
181
+ if value .IsValid () {
184
182
return value .Interface ()
185
183
}
186
184
187
185
case reflect .Ptr :
188
186
value := v .Elem ()
189
- if value .IsValid () && value . CanInterface () {
187
+ if value .IsValid () {
190
188
return Slice (value .Interface (), from , to )
191
189
}
192
190
@@ -205,7 +203,7 @@ func In(needle interface{}, array interface{}) bool {
205
203
case reflect .Array , reflect .Slice :
206
204
for i := 0 ; i < v .Len (); i ++ {
207
205
value := v .Index (i )
208
- if value .IsValid () && value . CanInterface () {
206
+ if value .IsValid () {
209
207
if Equal (value .Interface (), needle ).(bool ) {
210
208
return true
211
209
}
@@ -237,7 +235,7 @@ func In(needle interface{}, array interface{}) bool {
237
235
238
236
case reflect .Ptr :
239
237
value := v .Elem ()
240
- if value .IsValid () && value . CanInterface () {
238
+ if value .IsValid () {
241
239
return In (needle , value .Interface ())
242
240
}
243
241
return false
0 commit comments