refactor(form_mapping.go): mapping ptr, struct and map (#1749)

* refactor(form_mapping.go): mapping ptr, struct and map

* fix #1672 correct work with ptr - not create value if field is not set
* avoid allocations on strings.Split() - change to strings.Index()
* fix #610 tag value "-" is mean ignoring field
* struct fields mapped like json.Unmarshal
* map fields mapped like json.Unmarshal

* fix after @thinkerou review
This commit is contained in:
Dmitry Kutakov
2019-03-03 09:39:43 +03:00
committed by 田欧
parent 893c6cae07
commit 0d50ce8597
4 changed files with 341 additions and 150 deletions

View File

@ -1836,24 +1836,6 @@ $ curl "http://localhost:8080/getd?field_x=hello&field_d=world"
{"d":"world","x":{"FieldX":"hello"}}
```
**NOTE**: NOT support the follow style struct:
```go
type StructX struct {
X struct {} `form:"name_x"` // HERE have form
}
type StructY struct {
Y StructX `form:"name_y"` // HERE have form
}
type StructZ struct {
Z *StructZ `form:"name_z"` // HERE have form
}
```
In a word, only support nested custom struct which have no `form` now.
### Try to bind body into different structs
The normal methods for binding request body consumes `c.Request.Body` and they