修复Number转换BUG
This commit is contained in:
parent
80e62625f2
commit
dfae2fda76
@ -43,7 +43,7 @@ func Number(gjsonResult gjson.Result, numberReceiver any) error {
|
|||||||
// Date : 11:19 2024/11/27
|
// Date : 11:19 2024/11/27
|
||||||
func Int[T int8 | int16 | int32 | int64 | int](gjsonResult gjson.Result) (T, error) {
|
func Int[T int8 | int16 | int32 | int64 | int](gjsonResult gjson.Result) (T, error) {
|
||||||
var intResult T
|
var intResult T
|
||||||
if err := Number[T](gjsonResult, &intResult); nil != err {
|
if err := Number(gjsonResult, &intResult); nil != err {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
return intResult, nil
|
return intResult, nil
|
||||||
@ -56,7 +56,7 @@ func Int[T int8 | int16 | int32 | int64 | int](gjsonResult gjson.Result) (T, err
|
|||||||
// Date : 11:21 2024/11/27
|
// Date : 11:21 2024/11/27
|
||||||
func Uint[T uint8 | uint16 | uint32 | uint64 | uint](gjsonResult gjson.Result) (T, error) {
|
func Uint[T uint8 | uint16 | uint32 | uint64 | uint](gjsonResult gjson.Result) (T, error) {
|
||||||
var uintResult T
|
var uintResult T
|
||||||
if err := Number[T](gjsonResult, &uintResult); nil != err {
|
if err := Number(gjsonResult, &uintResult); nil != err {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
return uintResult, nil
|
return uintResult, nil
|
||||||
@ -69,7 +69,7 @@ func Uint[T uint8 | uint16 | uint32 | uint64 | uint](gjsonResult gjson.Result) (
|
|||||||
// Date : 11:24 2024/11/27
|
// Date : 11:24 2024/11/27
|
||||||
func Float[T float32 | float64](gjsonResult gjson.Result) (T, error) {
|
func Float[T float32 | float64](gjsonResult gjson.Result) (T, error) {
|
||||||
var floatResult T
|
var floatResult T
|
||||||
if err := Number[T](gjsonResult, &floatResult); nil != err {
|
if err := Number(gjsonResult, &floatResult); nil != err {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
return floatResult, nil
|
return floatResult, nil
|
||||||
@ -126,7 +126,7 @@ func Any(sourceValue gjson.Result) (any, error) {
|
|||||||
if strings.Contains(sourceValue.String(), ".") {
|
if strings.Contains(sourceValue.String(), ".") {
|
||||||
// 小数
|
// 小数
|
||||||
var res float64
|
var res float64
|
||||||
if err := Number[float64](sourceValue, &res); nil != err {
|
if err := Number(sourceValue, &res); nil != err {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return res, nil
|
return res, nil
|
||||||
@ -135,14 +135,14 @@ func Any(sourceValue gjson.Result) (any, error) {
|
|||||||
if strings.HasPrefix(sourceValue.String(), "-") {
|
if strings.HasPrefix(sourceValue.String(), "-") {
|
||||||
// 负数
|
// 负数
|
||||||
var res int64
|
var res int64
|
||||||
if err := Number[int64](sourceValue, &res); nil != err {
|
if err := Number(sourceValue, &res); nil != err {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return res, nil
|
return res, nil
|
||||||
} else {
|
} else {
|
||||||
// 正数
|
// 正数
|
||||||
var res uint64
|
var res uint64
|
||||||
if err := Number[uint64](sourceValue, &res); nil != err {
|
if err := Number(sourceValue, &res); nil != err {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return res, nil
|
return res, nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user