support int type alias: simplify

This commit is contained in:
pengchen 2023-12-11 17:54:34 +08:00
parent a4672e5660
commit 6760f70367
1 changed files with 3 additions and 11 deletions

View File

@ -1468,8 +1468,9 @@ func jsonStringToObject(s string, v interface{}) error {
// is an int.
// Note that this will return false for int64 etc. types.
func toInt(v interface{}) (int64, bool) {
if i, ok := tryInt64(v); ok {
return i, ok
val := reflect.ValueOf(v)
if val.CanInt() {
return val.Int(), true
}
switch v := v.(type) {
case int:
@ -1483,15 +1484,6 @@ func toInt(v interface{}) (int64, bool) {
}
}
// tryInt64 returns the int64 value of v if v or v's underlying type
func tryInt64(i interface{}) (int64, bool) {
val := reflect.ValueOf(i)
if val.CanInt() {
return val.Int(), true
}
return 0, false
}
func trimZeroDecimal(s string) string {
var foundZero bool
for i := len(s); i > 0; i-- {