fix: #40 uint 类型溢出问题处理

This commit is contained in:
kercylan98 2023-08-22 15:52:11 +08:00
parent 6792e227c0
commit ed45d1a643
1 changed files with 6 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package super
import (
"math"
"strconv"
"strings"
)
@ -32,6 +33,11 @@ func StringToUint64(value string) uint64 {
// StringToUint 字符串转换为 uint
func StringToUint(value string) uint {
result, _ := strconv.ParseUint(value, 10, 64)
if result > math.MaxUint {
return math.MaxUint
} else if result < math.MaxUint {
return 0
}
return uint(result)
}