mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-16 21:32:11 +08:00
Merge 6da4dad20dbf8d8e904eaafcda2adaa662be1858 into 18392f589f7ae55f0d911efd6b9dcb67a56006e1
This commit is contained in:
commit
6ba830d4cd
@ -329,11 +329,7 @@ func (c *Context) BindJSON(obj interface{}) error {
|
||||
// BindWith binds the passed struct pointer using the specified binding engine.
|
||||
// See the binding package.
|
||||
func (c *Context) BindWith(obj interface{}, b binding.Binding) error {
|
||||
if err := b.Bind(c.Request, obj); err != nil {
|
||||
c.AbortWithError(400, err).SetType(ErrorTypeBind)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return b.Bind(c.Request, obj)
|
||||
}
|
||||
|
||||
// ClientIP implements a best effort algorithm to return the real client IP, it parses
|
||||
|
@ -703,7 +703,7 @@ func TestContextBindWithJSON(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestContextBadAutoBind(t *testing.T) {
|
||||
c, w, _ := CreateTestContext()
|
||||
c, _, _ := CreateTestContext()
|
||||
c.Request, _ = http.NewRequest("POST", "http://example.com", bytes.NewBufferString("\"foo\":\"bar\", \"bar\":\"foo\"}"))
|
||||
c.Request.Header.Add("Content-Type", MIMEJSON)
|
||||
var obj struct {
|
||||
@ -711,14 +711,9 @@ func TestContextBadAutoBind(t *testing.T) {
|
||||
Bar string `json:"bar"`
|
||||
}
|
||||
|
||||
assert.False(t, c.IsAborted())
|
||||
assert.Error(t, c.Bind(&obj))
|
||||
c.Writer.WriteHeaderNow()
|
||||
|
||||
assert.Empty(t, obj.Bar)
|
||||
assert.Empty(t, obj.Foo)
|
||||
assert.Equal(t, w.Code, 400)
|
||||
assert.True(t, c.IsAborted())
|
||||
}
|
||||
|
||||
func TestContextGolangContext(t *testing.T) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user