From 068942b5ce84ee37c62b0b52d3dad8cdb0db16eb Mon Sep 17 00:00:00 2001 From: daheige Date: Wed, 14 Jul 2021 23:02:49 +0800 Subject: [PATCH] code style adjust --- binding/form_mapping.go | 7 ++++--- binding/form_mapping_test.go | 2 +- binding/multipart_form_mapping.go | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/binding/form_mapping.go b/binding/form_mapping.go index cb66dd4a..743ee19d 100644 --- a/binding/form_mapping.go +++ b/binding/form_mapping.go @@ -17,7 +17,8 @@ import ( ) var ( - errUnknownType = errors.New("unknown type") + // ErrUnknownType unknown type + ErrUnknownType = errors.New("unknown type") // ErrConvertMapStringSlice can not covert to map[string][]string ErrConvertMapStringSlice = errors.New("can not convert to map slices of strings") @@ -164,7 +165,7 @@ func tryToSetValue(value reflect.Value, field reflect.StructField, setter setter return setter.TrySet(value, field, tagValue, setOpt) } -func setByForm(value reflect.Value, field reflect.StructField, form map[string][]string, tagValue string, opt setOptions) (isSetted bool, err error) { +func setByForm(value reflect.Value, field reflect.StructField, form map[string][]string, tagValue string, opt setOptions) (bool, error) { vs, ok := form[tagValue] if !ok && !opt.isDefaultExists { return false, nil @@ -240,7 +241,7 @@ func setWithProperType(val string, value reflect.Value, field reflect.StructFiel case reflect.Map: return json.Unmarshal(bytesconv.StringToBytes(val), value.Addr().Interface()) default: - return errUnknownType + return ErrUnknownType } return nil } diff --git a/binding/form_mapping_test.go b/binding/form_mapping_test.go index 608594e2..51f6d19c 100644 --- a/binding/form_mapping_test.go +++ b/binding/form_mapping_test.go @@ -124,7 +124,7 @@ func TestMappingUnknownFieldType(t *testing.T) { err := mappingByPtr(&s, formSource{"U": {"unknown"}}, "form") assert.Error(t, err) - assert.Equal(t, errUnknownType, err) + assert.Equal(t, ErrUnknownType, err) } func TestMappingURI(t *testing.T) { diff --git a/binding/multipart_form_mapping.go b/binding/multipart_form_mapping.go index 69c0a544..b8887105 100644 --- a/binding/multipart_form_mapping.go +++ b/binding/multipart_form_mapping.go @@ -32,7 +32,7 @@ func (r *multipartRequest) TrySet(value reflect.Value, field reflect.StructField return setByForm(value, field, r.MultipartForm.Value, key, opt) } -func setByMultipartFormFile(value reflect.Value, field reflect.StructField, files []*multipart.FileHeader) (isSetted bool, err error) { +func setByMultipartFormFile(value reflect.Value, field reflect.StructField, files []*multipart.FileHeader) (bool, error) { switch value.Kind() { case reflect.Ptr: switch value.Interface().(type) { @@ -48,7 +48,7 @@ func setByMultipartFormFile(value reflect.Value, field reflect.StructField, file } case reflect.Slice: slice := reflect.MakeSlice(value.Type(), len(files), len(files)) - isSetted, err = setArrayOfMultipartFormFiles(slice, field, files) + isSetted, err := setArrayOfMultipartFormFiles(slice, field, files) if err != nil || !isSetted { return isSetted, err } @@ -60,7 +60,7 @@ func setByMultipartFormFile(value reflect.Value, field reflect.StructField, file return false, ErrMultiFileHeader } -func setArrayOfMultipartFormFiles(value reflect.Value, field reflect.StructField, files []*multipart.FileHeader) (isSetted bool, err error) { +func setArrayOfMultipartFormFiles(value reflect.Value, field reflect.StructField, files []*multipart.FileHeader) (bool, error) { if value.Len() != len(files) { return false, ErrMultiFileHeaderLenInvalid }