Skip to content

Commit

Permalink
reverse new Bind* arguments to make them more in line with context be…
Browse files Browse the repository at this point in the history
…st practices (context should be the first argument)
  • Loading branch information
aldas committed Dec 8, 2020
1 parent f2ab073 commit 4d59855
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type (
)

// BindRouteParams binds route params to bindable object
func (b *DefaultBinder) BindRouteParams(i interface{}, c Context) error {
func (b *DefaultBinder) BindRouteParams(c Context, i interface{}) error {
names := c.ParamNames()
values := c.ParamValues()
params := map[string][]string{}
Expand All @@ -45,7 +45,7 @@ func (b *DefaultBinder) BindRouteParams(i interface{}, c Context) error {
}

// BindQueryParams binds query params to bindable object
func (b *DefaultBinder) BindQueryParams(i interface{}, c Context) error {
func (b *DefaultBinder) BindQueryParams(c Context, i interface{}) error {
if err := b.bindData(i, c.QueryParams(), "query"); err != nil {
return NewHTTPError(http.StatusBadRequest, err.Error()).SetInternal(err)
}
Expand All @@ -57,7 +57,7 @@ func (b *DefaultBinder) BindQueryParams(i interface{}, c Context) error {
// which parses form data from BOTH URL and BODY if content type is not MIMEMultipartForm
// See non-MIMEMultipartForm: https://golang.org/pkg/net/http/#Request.ParseForm
// See MIMEMultipartForm: https://golang.org/pkg/net/http/#Request.ParseMultipartForm
func (b *DefaultBinder) BindBody(i interface{}, c Context) (err error) {
func (b *DefaultBinder) BindBody(c Context, i interface{}) (err error) {
req := c.Request()
if req.ContentLength == 0 {
return
Expand Down Expand Up @@ -99,13 +99,13 @@ func (b *DefaultBinder) BindBody(i interface{}, c Context) (err error) {

// Bind implements the `Binder#Bind` function.
func (b *DefaultBinder) Bind(i interface{}, c Context) (err error) {
if err := b.BindRouteParams(i, c); err != nil {
if err := b.BindRouteParams(c, i); err != nil {
return err
}
if err = b.BindQueryParams(i, c); err != nil {
if err = b.BindQueryParams(c, i); err != nil {
return err
}
return b.BindBody(i, c)
return b.BindBody(c, i)
}

func (b *DefaultBinder) bindData(ptr interface{}, data map[string][]string, tag string) error {
Expand Down
2 changes: 1 addition & 1 deletion bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ func TestDefaultBinder_BindBody(t *testing.T) {
}
b := new(DefaultBinder)

err := b.BindBody(bindTarget, c)
err := b.BindBody(c, bindTarget)
if tc.expectError != "" {
assert.EqualError(t, err, tc.expectError)
} else {
Expand Down

0 comments on commit 4d59855

Please sign in to comment.