/
swalker.go
53 lines (44 loc) · 912 Bytes
/
swalker.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
45
46
47
48
49
50
51
52
53
package swalker
import (
"reflect"
)
// ExpType : type of Expression
type ExpType int
const (
// Property : ExpType
Property ExpType = iota
// Indexing : Exptype
Indexing
)
// Expressions : parsed expressions
type Expressions []*Expression
// Expression : element of expressions
type Expression struct {
Type ExpType
Name string
Index int
}
func unwrap(v *reflect.Value) *reflect.Value {
if v.Kind() == reflect.Interface {
org := v.Elem() // Get rid of the wrapping interface
return &org
}
return v
}
func indirecte(v *reflect.Value) *reflect.Value {
indirected := reflect.Indirect(*v)
return &indirected
}
func isNil(v *reflect.Value) bool {
if v == nil {
return true
}
v = indirecte(v)
switch v.Kind() {
case reflect.Invalid:
return true
case reflect.Array, reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Slice:
return v.IsNil()
}
return false
}