修复Number转换BUG

This commit is contained in:
白茶清欢 2025-05-24 18:50:31 +08:00
parent 80e62625f2
commit dfae2fda76

View File

@ -43,7 +43,7 @@ func Number(gjsonResult gjson.Result, numberReceiver any) error {
// Date : 11:19 2024/11/27
func Int[T int8 | int16 | int32 | int64 | int](gjsonResult gjson.Result) (T, error) {
var intResult T
if err := Number[T](gjsonResult, &intResult); nil != err {
if err := Number(gjsonResult, &intResult); nil != err {
return 0, err
}
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
func Uint[T uint8 | uint16 | uint32 | uint64 | uint](gjsonResult gjson.Result) (T, error) {
var uintResult T
if err := Number[T](gjsonResult, &uintResult); nil != err {
if err := Number(gjsonResult, &uintResult); nil != err {
return 0, err
}
return uintResult, nil
@ -69,7 +69,7 @@ func Uint[T uint8 | uint16 | uint32 | uint64 | uint](gjsonResult gjson.Result) (
// Date : 11:24 2024/11/27
func Float[T float32 | float64](gjsonResult gjson.Result) (T, error) {
var floatResult T
if err := Number[T](gjsonResult, &floatResult); nil != err {
if err := Number(gjsonResult, &floatResult); nil != err {
return 0, err
}
return floatResult, nil
@ -126,7 +126,7 @@ func Any(sourceValue gjson.Result) (any, error) {
if strings.Contains(sourceValue.String(), ".") {
// 小数
var res float64
if err := Number[float64](sourceValue, &res); nil != err {
if err := Number(sourceValue, &res); nil != err {
return nil, err
}
return res, nil
@ -135,14 +135,14 @@ func Any(sourceValue gjson.Result) (any, error) {
if strings.HasPrefix(sourceValue.String(), "-") {
// 负数
var res int64
if err := Number[int64](sourceValue, &res); nil != err {
if err := Number(sourceValue, &res); nil != err {
return nil, err
}
return res, nil
} else {
// 正数
var res uint64
if err := Number[uint64](sourceValue, &res); nil != err {
if err := Number(sourceValue, &res); nil != err {
return nil, err
}
return res, nil