Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save smallnest/5b789d52af64fb59d1a4d199fc03e696 to your computer and use it in GitHub Desktop.
Save smallnest/5b789d52af64fb59d1a4d199fc03e696 to your computer and use it in GitHub Desktop.
```go
func isNil(i interface{}) bool {
return i == nil || reflect.ValueOf(i).IsNil()
}
```
better:
```go
func isNilFixed(i interface{}) bool {
if i == nil {
return true
}
switch reflect.TypeOf(i).Kind() {
case reflect.Ptr, reflect.Map, reflect.Array, reflect.Chan, reflect.Slice:
return reflect.ValueOf(i).IsNil()
}
return false
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment