mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-17 22:32:26 +08:00
code style adjust
This commit is contained in:
parent
3863064235
commit
f4dc3d3fd9
@ -160,7 +160,7 @@ func tryToSetValue(value reflect.Value, field reflect.StructField, setter setter
|
|||||||
return setter.TrySet(value, field, tagValue, setOpt)
|
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]
|
vs, ok := form[tagValue]
|
||||||
if !ok && !opt.isDefaultExists {
|
if !ok && !opt.isDefaultExists {
|
||||||
return false, nil
|
return false, nil
|
||||||
|
@ -13,16 +13,21 @@ import (
|
|||||||
"github.com/gin-gonic/gin/internal/json"
|
"github.com/gin-gonic/gin/internal/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
// EnableDecoderUseNumber is used to call the UseNumber method on the JSON
|
var (
|
||||||
// Decoder instance. UseNumber causes the Decoder to unmarshal a number into an
|
// EnableDecoderUseNumber is used to call the UseNumber method on the JSON
|
||||||
// interface{} as a Number instead of as a float64.
|
// Decoder instance. UseNumber causes the Decoder to unmarshal a number into an
|
||||||
var EnableDecoderUseNumber = false
|
// interface{} as a Number instead of as a float64.
|
||||||
|
EnableDecoderUseNumber = false
|
||||||
|
|
||||||
// EnableDecoderDisallowUnknownFields is used to call the DisallowUnknownFields method
|
// EnableDecoderDisallowUnknownFields is used to call the DisallowUnknownFields method
|
||||||
// on the JSON Decoder instance. DisallowUnknownFields causes the Decoder to
|
// on the JSON Decoder instance. DisallowUnknownFields causes the Decoder to
|
||||||
// return an error when the destination is a struct and the input contains object
|
// return an error when the destination is a struct and the input contains object
|
||||||
// keys which do not match any non-ignored, exported fields in the destination.
|
// keys which do not match any non-ignored, exported fields in the destination.
|
||||||
var EnableDecoderDisallowUnknownFields = false
|
EnableDecoderDisallowUnknownFields = false
|
||||||
|
|
||||||
|
// ErrRequestJsonInvalid request json invalid
|
||||||
|
ErrRequestJsonInvalid = errors.New("invalid request")
|
||||||
|
)
|
||||||
|
|
||||||
type jsonBinding struct{}
|
type jsonBinding struct{}
|
||||||
|
|
||||||
@ -32,7 +37,7 @@ func (jsonBinding) Name() string {
|
|||||||
|
|
||||||
func (jsonBinding) Bind(req *http.Request, obj interface{}) error {
|
func (jsonBinding) Bind(req *http.Request, obj interface{}) error {
|
||||||
if req == nil || req.Body == nil {
|
if req == nil || req.Body == nil {
|
||||||
return errors.New("invalid request")
|
return ErrRequestJsonInvalid
|
||||||
}
|
}
|
||||||
return decodeJSON(req.Body, obj)
|
return decodeJSON(req.Body, obj)
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ func (r *multipartRequest) TrySet(value reflect.Value, field reflect.StructField
|
|||||||
return setByForm(value, field, r.MultipartForm.Value, key, opt)
|
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() {
|
switch value.Kind() {
|
||||||
case reflect.Ptr:
|
case reflect.Ptr:
|
||||||
switch value.Interface().(type) {
|
switch value.Interface().(type) {
|
||||||
@ -48,7 +48,7 @@ func setByMultipartFormFile(value reflect.Value, field reflect.StructField, file
|
|||||||
}
|
}
|
||||||
case reflect.Slice:
|
case reflect.Slice:
|
||||||
slice := reflect.MakeSlice(value.Type(), len(files), len(files))
|
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 {
|
if err != nil || !isSetted {
|
||||||
return isSetted, err
|
return isSetted, err
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ func setByMultipartFormFile(value reflect.Value, field reflect.StructField, file
|
|||||||
return false, ErrMultiFileHeader
|
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) {
|
if value.Len() != len(files) {
|
||||||
return false, ErrMultiFileHeaderLenInvalid
|
return false, ErrMultiFileHeaderLenInvalid
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user