18 lines
363 B
Go
18 lines
363 B
Go
package nilutil
|
|
|
|
import "reflect"
|
|
|
|
// IsNil reports whether v is nil or an interface holding a typed nil value.
|
|
func IsNil(v any) bool {
|
|
if v == nil {
|
|
return true
|
|
}
|
|
rv := reflect.ValueOf(v)
|
|
switch rv.Kind() {
|
|
case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Pointer, reflect.Slice:
|
|
return rv.IsNil()
|
|
default:
|
|
return false
|
|
}
|
|
}
|