Well, am trying to check for nil in golang,
Looks like this utility may help
func IsNil(i interface{}) bool {
if i == nil {
return true
}
val := reflect.ValueOf(i)
kind := val.Kind()
switch kind {
case reflect.Ptr, reflect.Chan, reflect.Func, reflect.Map, reflect.Slice, reflect.Interface:
return val.IsNil()
}
return false
}
need to import "reflect" package.
Looks like this utility may help
func IsNil(i interface{}) bool {
if i == nil {
return true
}
val := reflect.ValueOf(i)
kind := val.Kind()
switch kind {
case reflect.Ptr, reflect.Chan, reflect.Func, reflect.Map, reflect.Slice, reflect.Interface:
return val.IsNil()
}
return false
}
need to import "reflect" package.
No comments:
Post a Comment