forked from Velocidex/velociraptor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnil.go
43 lines (34 loc) · 853 Bytes
/
nil.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
package utils
import (
"reflect"
"runtime"
"www.velocidex.com/golang/vfilter/types"
)
// We need to do this stupid check because Go does not allow
// comparison to nil with interfaces.
func IsNil(v interface{}) bool {
if v == nil {
return true
}
switch v.(type) {
case types.Null, *types.Null:
return true
}
switch reflect.TypeOf(v).Kind() {
case reflect.Ptr, reflect.Map, reflect.Chan, reflect.Slice:
//use of IsNil method
return reflect.ValueOf(v).IsNil()
default:
return false
}
}
// Compare two functions by name. This allows setting a constant func
// as a parameter.
func CompareFuncs(a func(), b func()) bool {
if a == nil || b == nil {
return false
}
name_a := runtime.FuncForPC(reflect.ValueOf(a).Pointer()).Name()
name_b := runtime.FuncForPC(reflect.ValueOf(b).Pointer()).Name()
return name_a == name_b
}