Fix #216: Enable to call binding multiple times in some formats (#1341)

* 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 2c82901ceab6ae53730a3cfcd9839bee11a08f13.

* Use private-like key for body bytes

* Add tests for BindingBody & ShouldBindBodyWith

* Add note for README

* Remove redundant space between sentences
This commit is contained in:
JINNOUCHI Yasushi
2018-05-11 11:33:33 +09:00
committed by Bo-Yi Wu
parent 6e09ef03b0
commit 995fa8e9ce
9 changed files with 279 additions and 10 deletions

View File

@ -29,6 +29,13 @@ type Binding interface {
Bind(*http.Request, interface{}) error
}
// BindingBody adds BindBody method to Binding. BindBody is similar with Bind,
// but it reads the body from supplied bytes instead of req.Body.
type BindingBody interface {
Binding
BindBody([]byte, interface{}) error
}
// StructValidator is the minimal interface which needs to be implemented in
// order for it to be used as the validator engine for ensuring the correctness
// of the reqest. Gin provides a default implementation for this using