Skip to content

Commit

Permalink
Merge pull request #5 from cblk/master
Browse files Browse the repository at this point in the history
feat(tonic): use shouldBind for default binding hook
  • Loading branch information
lencyforce authored Jun 23, 2020
2 parents 95a45ea + 2f7f0a6 commit 393d1a6
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 15 deletions.
10 changes: 0 additions & 10 deletions tonic/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,11 @@ func Handler(h interface{}, status int, options ...func(*Route)) gin.HandlerFunc
handleError(c, bindError)
return
}
// Bind query-parameters.
if err := bind(c, input, QueryTag, extractQuery); err != nil {
handleError(c, err)
return
}
// Bind path arguments.
if err := bind(c, input, PathTag, extractPath); err != nil {
handleError(c, err)
return
}
// Bind headers.
if err := bind(c, input, HeaderTag, extractHeader); err != nil {
handleError(c, err)
return
}
// validating query and path inputs if they have a validate tag
initValidator()
args = append(args, input)
Expand Down
6 changes: 1 addition & 5 deletions tonic/tonic.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"time"

"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
validator "gopkg.in/go-playground/validator.v9"
)

Expand Down Expand Up @@ -93,10 +92,7 @@ var DefaultBindingHook BindHook = DefaultBindingHookMaxBodyBytes(DefaultMaxBodyB
func DefaultBindingHookMaxBodyBytes(maxBodyBytes int64) BindHook {
return func(c *gin.Context, i interface{}) error {
c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, maxBodyBytes)
if c.Request.ContentLength == 0 || c.Request.Method == http.MethodGet {
return nil
}
if err := c.ShouldBindWith(i, binding.JSON); err != nil && err != io.EOF {
if err := c.ShouldBind(i); err != nil && err != io.EOF {
return err
}
return nil
Expand Down

0 comments on commit 393d1a6

Please sign in to comment.