From 6760f70367d3beb9905edb41ef1ffdb2b9244092 Mon Sep 17 00:00:00 2001 From: pengchen Date: Mon, 11 Dec 2023 17:54:34 +0800 Subject: [PATCH] support int type alias: simplify --- caste.go | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/caste.go b/caste.go index 470f94e..247c898 100644 --- a/caste.go +++ b/caste.go @@ -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-- {