Created
March 16, 2021 03:12
-
-
Save e7/ef68c64426b9b15dcaa025908fbb9a69 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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