github.com/Finschia/ostracon@v1.1.5/types/utils.go (about) 1 package types 2 3 import ( 4 "reflect" 5 "time" 6 ) 7 8 type StepDuration struct { 9 Start time.Time 10 End time.Time 11 } 12 13 func (sd *StepDuration) GetDuration() float64 { 14 if sd.End.After(sd.Start) { 15 return float64(sd.End.Sub(sd.Start).Microseconds()) / 1000 16 } 17 return 0 18 } 19 20 // Go lacks a simple and safe way to see if something is a typed nil. 21 // See: 22 // - https://dave.cheney.net/2017/08/09/typed-nils-in-go-2 23 // - https://groups.google.com/forum/#!topic/golang-nuts/wnH302gBa4I/discussion 24 // - https://github.com/golang/go/issues/21538 25 func isTypedNil(o interface{}) bool { 26 rv := reflect.ValueOf(o) 27 switch rv.Kind() { 28 case reflect.Chan, reflect.Func, reflect.Map, reflect.Ptr, reflect.Slice: 29 return rv.IsNil() 30 default: 31 return false 32 } 33 } 34 35 // Returns true if it has zero length. 36 func isEmpty(o interface{}) bool { 37 rv := reflect.ValueOf(o) 38 switch rv.Kind() { 39 case reflect.Array, reflect.Chan, reflect.Map, reflect.Slice, reflect.String: 40 return rv.Len() == 0 41 default: 42 return false 43 } 44 }