In the go, the stack burst will occupy 1G memory, the error message is as follows
```runtime: goroutine stack exceeds 1000000000-byte limit```
If it is a user of gin, the structure of the circular reference is defined on the server side,
and the server memory may be used up as long as 100 go processes, and even the server may be down.
So I suggest that the mapping function should add a limit on the number of calls,
and the number of times can be configured.
Of course, I tried several other modifications when I solved the stackoverflow problem described in #1978,
but it was not compatible with the existing API, so I did not adopt the solution I tried.
* support bind http header param #1956
update #1956
```
package main
import (
"fmt"
"github.com/gin-gonic/gin"
)
type testHeader struct {
Rate int `header:"Rate"`
Domain string `header:"Domain"`
}
func main() {
r := gin.Default()
r.GET("/", func(c *gin.Context) {
h := testHeader{}
if err := c.ShouldBindHeader(&h); err != nil {
c.JSON(200, err)
}
fmt.Printf("%#v\n", h)
c.JSON(200, gin.H{"Rate": h.Rate, "Domain": h.Domain})
})
r.Run()
// client
// curl -H "rate:300" -H "domain:music" 127.0.0.1:8080/
// output
// {"Domain":"music","Rate":300}
}
```
* add unit test
* Modify the code to get the http header
When the http header is obtained in the standard library,
the key value will be modified by the CanonicalMIMEHeaderKey function,
and finally the value of the http header will be obtained from the map.
As follows.
```go
func (h MIMEHeader) Get(key string) string {
// ...
v := h[CanonicalMIMEHeaderKey(key)]
// ...
}
```
This pr also follows this modification
* Thanks to vkd for suggestions, modifying code
* Increase test coverage
env GOPATH=`pwd` go test github.com/gin-gonic/gin/binding -coverprofile=cover.prof
ok github.com/gin-gonic/gin/binding 0.015s coverage: 100.0% of statements
* Rollback check code
* add use case to README.md
* move tests of mapping to separate test file
make 100% coverage of form_mapping.go from form_mapping_test.go file
* fix tests for go 1.6
go 1.6 doesn't support `t.Run(...)` subtests
* refactor(form_mapping.go): mapping multipart request
* add checkers for a types to match with the setter interface
* form_mapping.go: rename method name on setter interface, add comments
* fix style of comments
* 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
* support bind uri (1)
* uri binding successful run
* fix vet warning: github.com/gin-gonic/gin/internal.Param composite literal uses unkeyed fields
* fix code style
* update function name
* fix test function signature
* add test for CanSet
* update readme and add test case
* remove internal.Params
* add coverage
* fix warning
* Add interface to read body bytes in binding
* Add BindingBody implementation for some binding
* Fix to use `BindBodyBytesKey` for key
* Revert "Fix to use `BindBodyBytesKey` for key"
This reverts commit 2c82901cea.
* Use private-like key for body bytes
* Add tests for BindingBody & ShouldBindBodyWith
* Add note for README
* Remove redundant space between sentences
* support default value for form
* fix bug for nil interface
* use SplitN and optimization code
* add test case
* add test cases for form(own default value)
* fix invalid code
* fix code indent
* assert order
* fix(binding): Expose validator engine used by the default Validator
- Add func ValidatorEngine for returning the underlying validator engine used
in the default StructValidator implementation.
- Remove the function RegisterValidation from the StructValidator interface
which made it immpossible to use a StructValidator implementation without the
validator.v8 library.
- Update and rename test for registering validation
Test{RegisterValidation => ValidatorEngine}.
- Update readme and example for registering custom validation.
- Add example for registering struct level validation.
- Add documentation for the following binding funcs/types:
- Binding interface
- StructValidator interface
- Validator instance
- Binding implementations
- Default func
* fix(binding): Move validator engine getter inside interface
* docs: rm date cmd from custom validation demo
* feat(binding): Add support for custom validation tags
* docs: Add example for custom validation tag
* test(binding): Add test for registering custom validation