mirror of https://github.com/spf13/cast.git
support int type alias: simplify
This commit is contained in:
parent
a4672e5660
commit
6760f70367
14
caste.go
14
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-- {
|
||||
|
|
Loading…
Reference in New Issue