如何重写以下代码?
switch md.(type) {
case *amf0.EcmaArrayType:
ea := md.(*amf0.EcmaArrayType)
for k, v := range (*ea) {
log.Printf("%v = %v\n", k, v)
}
if width == 0 {width = uint16((*ea)["width"].(amf0.NumberType))}
if height == 0 {height = uint16((*ea)["height"].(amf0.NumberType))}
case *amf0.ObjectType:
ea := md.(*amf0.ObjectType)
for k, v := range (*ea) {
log.Printf("%v = %v\n", k, v)
}
if width == 0 {width = uint16((*ea)["width"].(amf0.NumberType))}
if height == 0 {height = uint16((*ea)["height"].(amf0.NumberType))}
}
它具有两个完全相同的块,用于不同类型。如果我声明了var ea interface{}上述开关状态,则range (*ea)由于编译错误而无法调用。
慕沐林林
相关分类