github.com/okex/exchain@v1.8.0/libs/tendermint/types/utils.go (about) 1 package types 2 3 import ( 4 jsoniter "github.com/json-iterator/go" 5 "reflect" 6 ) 7 8 var Json = jsoniter.ConfigCompatibleWithStandardLibrary 9 10 // Go lacks a simple and safe way to see if something is a typed nil. 11 // See: 12 // - https://dave.cheney.net/2017/08/09/typed-nils-in-go-2 13 // - https://groups.google.com/forum/#!topic/golang-nuts/wnH302gBa4I/discussion 14 // - https://github.com/golang/go/issues/21538 15 func isTypedNil(o interface{}) bool { 16 rv := reflect.ValueOf(o) 17 switch rv.Kind() { 18 case reflect.Chan, reflect.Func, reflect.Map, reflect.Ptr, reflect.Slice: 19 return rv.IsNil() 20 default: 21 return false 22 } 23 } 24 25 // Returns true if it has zero length. 26 func isEmpty(o interface{}) bool { 27 rv := reflect.ValueOf(o) 28 switch rv.Kind() { 29 case reflect.Array, reflect.Chan, reflect.Map, reflect.Slice, reflect.String: 30 return rv.Len() == 0 31 default: 32 return false 33 } 34 }