fix: #40 uint 类型溢出问题处理
This commit is contained in:
parent
6792e227c0
commit
ed45d1a643
|
@ -1,6 +1,7 @@
|
||||||
package super
|
package super
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
@ -32,6 +33,11 @@ func StringToUint64(value string) uint64 {
|
||||||
// StringToUint 字符串转换为 uint
|
// StringToUint 字符串转换为 uint
|
||||||
func StringToUint(value string) uint {
|
func StringToUint(value string) uint {
|
||||||
result, _ := strconv.ParseUint(value, 10, 64)
|
result, _ := strconv.ParseUint(value, 10, 64)
|
||||||
|
if result > math.MaxUint {
|
||||||
|
return math.MaxUint
|
||||||
|
} else if result < math.MaxUint {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
return uint(result)
|
return uint(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue