从一个map[string]interface{}中提取一个字段, 类型初步确定有string、float64(整数)
func GetCardTType(ctx *gin.Context, card map[string]interface{}) string {
val, _ := card["t"]
t := ""
switch valType := val.(type) {
case string:
t, _ = val.(string)
case float64:
vf, _ := val.(float64)
t = strconv.Itoa(int(vf))
default:
t = fmt.Sprintf("%+v", val)
zap_logger.Errorf(ctx, common.TAG_NAME, "unknown:%+v TypeOf t:%+v invalid card:%+v ", valType, reflect.TypeOf(val), card)
}
return t
}
网友评论