mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 09:00:20 +08:00
chore: coding style (#3413)
This commit is contained in:
parent
b9c0c0f8b5
commit
0c6eaeda9f
@ -618,7 +618,7 @@ func (u *Unmarshaler) processFieldPrimitiveWithJSONNumber(fieldType reflect.Type
|
||||
|
||||
target.SetFloat(fValue)
|
||||
default:
|
||||
return newTypeMismatchErrorWithHint(fullName, value.Type().String(), typeKind.String())
|
||||
return newTypeMismatchErrorWithHint(fullName, typeKind.String(), value.Type().String())
|
||||
}
|
||||
|
||||
SetValue(fieldType, value, target)
|
||||
@ -1054,8 +1054,9 @@ func newTypeMismatchError(name string) error {
|
||||
return fmt.Errorf("type mismatch for field %q", name)
|
||||
}
|
||||
|
||||
func newTypeMismatchErrorWithHint(name, errorType, rightType string) error {
|
||||
return fmt.Errorf("type mismatch for field %q, expected %q, got %q", name, rightType, errorType)
|
||||
func newTypeMismatchErrorWithHint(name, expectType, actualType string) error {
|
||||
return fmt.Errorf("type mismatch for field %q, expect %q, actual %q",
|
||||
name, expectType, actualType)
|
||||
}
|
||||
|
||||
func readKeys(key string) []string {
|
||||
|
@ -4991,10 +4991,12 @@ func TestUnmarshalerProcessFieldPrimitiveWithJSONNumber(t *testing.T) {
|
||||
value := reflect.ValueOf(&realValue) // pass a pointer to the value
|
||||
v := json.Number(expectValue)
|
||||
m := NewUnmarshaler("field")
|
||||
err := m.processFieldPrimitiveWithJSONNumber(fieldType, value.Elem(), v, &fieldOptionsWithContext{}, "field")
|
||||
err := m.processFieldPrimitiveWithJSONNumber(fieldType, value.Elem(), v,
|
||||
&fieldOptionsWithContext{}, "field")
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, "type mismatch for field \"field\", expected \"string\", got \"int\"", err.Error())
|
||||
assert.Equal(t, `type mismatch for field "field", expect "string", actual "int"`, err.Error())
|
||||
})
|
||||
|
||||
t.Run("right type", func(t *testing.T) {
|
||||
expectValue := int64(1)
|
||||
realValue := int64(1)
|
||||
@ -5002,10 +5004,10 @@ func TestUnmarshalerProcessFieldPrimitiveWithJSONNumber(t *testing.T) {
|
||||
value := reflect.ValueOf(&realValue) // pass a pointer to the value
|
||||
v := json.Number(strconv.FormatInt(expectValue, 10))
|
||||
m := NewUnmarshaler("field")
|
||||
err := m.processFieldPrimitiveWithJSONNumber(fieldType, value.Elem(), v, &fieldOptionsWithContext{}, "field")
|
||||
err := m.processFieldPrimitiveWithJSONNumber(fieldType, value.Elem(), v,
|
||||
&fieldOptionsWithContext{}, "field")
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func TestGetValueWithChainedKeys(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user