I would like to cast empty interface to map. Why is this not ok?
// q tarantool.Queue (https://github.com/tarantool/go-tarantool)
statRaw, _ := q.Statistic() // interface{}; map[tasks:map[taken:0 buried:0 ...] calls:map[put:1 delay:0 ...]]
type stat map[string]map[string]uint
_, ok := statRaw.(stat)
Your function returns a map[string]map[string]uint
, not a stat
. They are distinct types in go's type-system. Either type-assert to map[string]map[string]uint
or, in Go 1.9, you can create an alias instead:
statRaw, _ := q.Statistic()
type stat = map[string]map[string]uint
_, ok := statRaw.(stat)
Don't use a type alias for this kind of thing.
First type check, then convert:
statRaw, _ := q.Statistic()
raw, ok := statRaw.(map[string]map[string]uint)
if !ok {
return
}
type stat map[string]map[string]uint
my := stat(raw)