-
Notifications
You must be signed in to change notification settings - Fork 0
/
reflect.go
44 lines (36 loc) · 818 Bytes
/
reflect.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package revip
import (
"reflect"
"github.com/pkg/errors"
)
func indirectValue(reflectValue reflect.Value) reflect.Value {
if reflectValue.Kind() == reflect.Ptr {
return reflectValue.Elem()
}
return reflectValue
}
func indirectType(reflectType reflect.Type) reflect.Type {
if reflectType.Kind() == reflect.Ptr || reflectType.Kind() == reflect.Slice {
return reflectType.Elem()
}
return reflectType
}
func isNil(reflectValue reflect.Value) bool {
if reflectValue.Kind() == reflect.Ptr {
return reflectValue.IsNil()
}
return false
}
func expectKind(reflectType reflect.Type, ks ...reflect.Kind) error {
k := reflectType.Kind()
for _, ek := range ks {
if ek == k {
return nil
}
}
return errors.WithStack(&ErrUnexpectedKind{
Type: reflectType,
Got: k,
Expected: ks,
})
}