mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-09 17:59:36 +08:00
fix: ConvertToFloat64 support convert string to float64
This commit is contained in:
@@ -380,8 +380,18 @@ func ConvertToFloat64(val interface{}) (float64, error) {
|
|||||||
return float64(v), nil
|
return float64(v), nil
|
||||||
case int64:
|
case int64:
|
||||||
return float64(v), nil
|
return float64(v), nil
|
||||||
|
case string:
|
||||||
|
f, err := strconv.ParseFloat(v, 64)
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Str("value", v).
|
||||||
|
Msg("convert string to float64 failed")
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return f, nil
|
||||||
default:
|
default:
|
||||||
return 0, fmt.Errorf("invalid type for conversion to float64: %T, value: %+v", val, val)
|
log.Error().Interface("value", val).Type("type", val).
|
||||||
|
Msg("convert float64 failed")
|
||||||
|
return 0, errors.New("convert float64 error")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -396,7 +406,7 @@ func ConvertToFloat64Slice(val interface{}) ([]float64, error) {
|
|||||||
for i, v := range paramsSlice {
|
for i, v := range paramsSlice {
|
||||||
float64Slice[i], err = ConvertToFloat64(v)
|
float64Slice[i], err = ConvertToFloat64(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("val is not float64 slice")
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return float64Slice, nil
|
return float64Slice, nil
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
v5.0.0+2412231751
|
v5.0.0+2412232041
|
||||||
|
|||||||
Reference in New Issue
Block a user