mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 09:00:20 +08:00
chore: sort methods (#2470)
This commit is contained in:
parent
59c0013cd1
commit
ada2941e87
@ -205,10 +205,10 @@ func (u *Unmarshaler) processFieldNotFromString(field reflect.StructField, value
|
||||
return u.processFieldStruct(field, value, mapValue, fullName)
|
||||
case valueKind == reflect.Map && typeKind == reflect.Map:
|
||||
return u.fillMap(field, value, mapValue)
|
||||
case valueKind == reflect.String && typeKind == reflect.Slice:
|
||||
return u.fillSliceFromString(fieldType, value, mapValue)
|
||||
case valueKind == reflect.String && typeKind == reflect.Map:
|
||||
return u.fillMapFromString(value, mapValue)
|
||||
case valueKind == reflect.String && typeKind == reflect.Slice:
|
||||
return u.fillSliceFromString(fieldType, value, mapValue)
|
||||
case valueKind == reflect.String && derefedFieldType == durationType:
|
||||
return fillDurationValue(fieldType.Kind(), value, mapValue.(string))
|
||||
default:
|
||||
@ -444,6 +444,27 @@ func (u *Unmarshaler) fillMap(field reflect.StructField, value reflect.Value, ma
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *Unmarshaler) fillMapFromString(value reflect.Value, mapValue interface{}) error {
|
||||
if !value.CanSet() {
|
||||
return errValueNotSettable
|
||||
}
|
||||
|
||||
switch v := mapValue.(type) {
|
||||
case fmt.Stringer:
|
||||
if err := jsonx.UnmarshalFromString(v.String(), value.Addr().Interface()); err != nil {
|
||||
return err
|
||||
}
|
||||
case string:
|
||||
if err := jsonx.UnmarshalFromString(v, value.Addr().Interface()); err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
return errUnsupportedType
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *Unmarshaler) fillSlice(fieldType reflect.Type, value reflect.Value, mapValue interface{}) error {
|
||||
if !value.CanSet() {
|
||||
return errValueNotSettable
|
||||
@ -532,23 +553,6 @@ func (u *Unmarshaler) fillSliceFromString(fieldType reflect.Type, value reflect.
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *Unmarshaler) fillMapFromString(value reflect.Value, mapValue interface{}) error {
|
||||
switch v := mapValue.(type) {
|
||||
case fmt.Stringer:
|
||||
if err := jsonx.UnmarshalFromString(v.String(), value.Addr().Interface()); err != nil {
|
||||
return err
|
||||
}
|
||||
case string:
|
||||
if err := jsonx.UnmarshalFromString(v, value.Addr().Interface()); err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
return errUnsupportedType
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *Unmarshaler) fillSliceValue(slice reflect.Value, index int,
|
||||
baseKind reflect.Kind, value interface{}) error {
|
||||
ithVal := slice.Index(index)
|
||||
|
Loading…
Reference in New Issue
Block a user