Skip to content

Instantly share code, notes, and snippets.

@e7
Created March 16, 2021 03:12
Show Gist options
  • Save e7/ef68c64426b9b15dcaa025908fbb9a69 to your computer and use it in GitHub Desktop.
Save e7/ef68c64426b9b15dcaa025908fbb9a69 to your computer and use it in GitHub Desktop.
func NilInterface(i interface{}) bool {
iVal := reflect.ValueOf(i)
switch iVal.Kind() {
case reflect.Invalid:
return i == nil
case reflect.Chan, reflect.Map, reflect.Slice, reflect.Interface, reflect.Func:
fallthrough
case reflect.Ptr, reflect.UnsafePointer:
return iVal.IsNil()
default:
return false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment