mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-26 19:11:08 +01:00
refactor(serialization): simplify string conversion logic in Convert function
This commit is contained in:
@@ -441,28 +441,8 @@ func Convert(src reflect.Value, dst reflect.Value, checkValidateTag bool) gperr.
|
||||
return err
|
||||
}
|
||||
case dstT.Kind() == reflect.String:
|
||||
if src.Kind() == reflect.Bool { // bool to string
|
||||
if !dst.CanSet() {
|
||||
return ErrUnsettable.Subject(dstT.String())
|
||||
}
|
||||
dst.SetString(strconv.FormatBool(src.Bool()))
|
||||
return nil
|
||||
} else if gi.ReflectIsNumeric(src) { // numeric to string
|
||||
if !dst.CanSet() {
|
||||
return ErrUnsettable.Subject(dstT.String())
|
||||
}
|
||||
var strV string
|
||||
switch {
|
||||
case src.CanInt():
|
||||
strV = strconv.FormatInt(src.Int(), 10)
|
||||
case src.CanUint():
|
||||
strV = strconv.FormatUint(src.Uint(), 10)
|
||||
case src.CanFloat():
|
||||
strV = strconv.FormatFloat(src.Float(), 'f', -1, 64)
|
||||
}
|
||||
dst.SetString(strV)
|
||||
return nil
|
||||
}
|
||||
dst.SetString(gi.ReflectToStr(src))
|
||||
return nil
|
||||
case srcKind == reflect.Map: // map to map
|
||||
if src.Len() == 0 {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user