以下代码工作正常
var requestMap map[string]interface{}
for _, value := range requestMap {
switch v := value.(type) {
case []interface{}:
if len(v) == 0 {
// if is empty then no need to throw NA
return http.StatusOK, nil
}
case string:
if len(v) == 0 {
// if is empty then no need to throw NA
return http.StatusOK, nil
}
}
}
但是下面的代码给出了invalid argument for len function,我已经阅读了这个问题
var requestMap map[string]interface{}
for _, value := range requestMap {
switch v := value.(type) {
case []interface{}, string:
if len(v) == 0 {
// if is empty then no need to throw NA
return http.StatusOK, nil
}
}
}
这个 case 语句不足以识别[]interface{}或string作为值类型吗?为什么它仍在考虑interface{}作为参数len()
斯蒂芬大帝
holdtom
相关分类