diff --git a/binding/binding.go b/binding/binding.go index 703a1cf8..ddee22e6 100644 --- a/binding/binding.go +++ b/binding/binding.go @@ -32,9 +32,9 @@ type Binding interface { Bind(*http.Request, any) error } -// BindingBody adds BindBody method to Binding. BindBody is similar with Bind, +// Body 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 { +type Body interface { Binding BindBody([]byte, any) error } diff --git a/binding/binding_test.go b/binding/binding_test.go index b1edbf5a..d9746e26 100644 --- a/binding/binding_test.go +++ b/binding/binding_test.go @@ -1339,10 +1339,10 @@ func testProtoBodyBindingFail(t *testing.T, b Binding, name, path, badPath, body err := b.Bind(req, &obj) assert.Error(t, err) - invalid_obj := FooStruct{} + invalidobj := FooStruct{} req.Body = ioutil.NopCloser(strings.NewReader(`{"msg":"hello"}`)) req.Header.Add("Content-Type", MIMEPROTOBUF) - err = b.Bind(req, &invalid_obj) + err = b.Bind(req, &invalidobj) assert.Error(t, err) assert.Equal(t, err.Error(), "obj is not ProtoMessage") diff --git a/context.go b/context.go index 0fe13331..481020f1 100644 --- a/context.go +++ b/context.go @@ -716,7 +716,7 @@ func (c *Context) ShouldBindWith(obj any, b binding.Binding) error { // // NOTE: This method reads the body before binding. So you should use // ShouldBindWith for better performance if you need to call only once. -func (c *Context) ShouldBindBodyWith(obj any, bb binding.BindingBody) (err error) { +func (c *Context) ShouldBindBodyWith(obj any, bb binding.Body) (err error) { var body []byte if cb, ok := c.Get(BodyBytesKey); ok { if cbb, ok := cb.([]byte); ok { diff --git a/context_test.go b/context_test.go index fb46e679..88c45bc7 100644 --- a/context_test.go +++ b/context_test.go @@ -1801,7 +1801,7 @@ func TestContextShouldBindBodyWith(t *testing.T) { } for _, tt := range []struct { name string - bindingA, bindingB binding.BindingBody + bindingA, bindingB binding.Body bodyA, bodyB string }{ { diff --git a/githubapi_test.go b/githubapi_test.go index e74bddd5..5fe65a4b 100644 --- a/githubapi_test.go +++ b/githubapi_test.go @@ -296,8 +296,8 @@ func TestShouldBindUri(t *testing.T) { router.Handle(http.MethodGet, "/rest/:name/:id", func(c *Context) { var person Person assert.NoError(t, c.ShouldBindUri(&person)) - assert.True(t, "" != person.Name) - assert.True(t, "" != person.ID) + assert.True(t, person.Name != "") + assert.True(t, person.ID != "") c.String(http.StatusOK, "ShouldBindUri test OK") }) @@ -318,8 +318,8 @@ func TestBindUri(t *testing.T) { router.Handle(http.MethodGet, "/rest/:name/:id", func(c *Context) { var person Person assert.NoError(t, c.BindUri(&person)) - assert.True(t, "" != person.Name) - assert.True(t, "" != person.ID) + assert.True(t, person.Name != "") + assert.True(t, person.ID != "") c.String(http.StatusOK, "BindUri test OK") })