mirror of
https://github.com/fluencelabs/tendermint
synced 2025-07-31 04:01:55 +00:00
Add IsTypedNil
This commit is contained in:
18
common/nil.go
Normal file
18
common/nil.go
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
import "reflect"
|
||||||
|
|
||||||
|
// Go lacks a simple and safe way to see if something is a typed nil.
|
||||||
|
// See:
|
||||||
|
// - https://dave.cheney.net/2017/08/09/typed-nils-in-go-2
|
||||||
|
// - https://groups.google.com/forum/#!topic/golang-nuts/wnH302gBa4I/discussion
|
||||||
|
// - https://github.com/golang/go/issues/21538
|
||||||
|
func IsTypedNil(o interface{}) bool {
|
||||||
|
rv := reflect.ValueOf(o)
|
||||||
|
switch rv.Kind() {
|
||||||
|
case reflect.Chan, reflect.Func, reflect.Map, reflect.Ptr, reflect.Slice:
|
||||||
|
return rv.IsNil()
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user