Skip to content

Commit 70c1806

Browse files
committed
Fixed #988, Closed #989
Signed-off-by: Vishal Rana <[email protected]>
1 parent 1e9845a commit 70c1806

File tree

3 files changed

+5
-60
lines changed

3 files changed

+5
-60
lines changed

bind.go

-19
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ func (b *DefaultBinder) Bind(i interface{}, c Context) (err error) {
3939
}
4040
return NewHTTPError(http.StatusBadRequest, "Request body can't be empty")
4141
}
42-
if err = b.bindPathData(i, c); err != nil {
43-
return NewHTTPError(http.StatusBadRequest, err.Error())
44-
}
4542
ctype := req.Header.Get(HeaderContentType)
4643
switch {
4744
case strings.HasPrefix(ctype, MIMEApplicationJSON):
@@ -78,22 +75,6 @@ func (b *DefaultBinder) Bind(i interface{}, c Context) (err error) {
7875
return
7976
}
8077

81-
func (b *DefaultBinder) bindPathData(ptr interface{}, c Context) error {
82-
if reflect.TypeOf(ptr).Elem().Kind() == reflect.Slice {
83-
return nil
84-
}
85-
m := make(map[string][]string, len(c.ParamNames()))
86-
for _, key := range c.ParamNames() {
87-
m[key] = []string{c.Param(key)}
88-
}
89-
if len(m) >= 0 {
90-
if err := b.bindData(ptr, m, "param"); err != nil {
91-
return err
92-
}
93-
}
94-
return nil
95-
}
96-
9778
func (b *DefaultBinder) bindData(ptr interface{}, data map[string][]string, tag string) error {
9879
typ := reflect.TypeOf(ptr).Elem()
9980
val := reflect.ValueOf(ptr).Elem()

bind_test.go

-34
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ var values = map[string][]string{
118118
func TestBindJSON(t *testing.T) {
119119
testBindOkay(t, strings.NewReader(userJSON), MIMEApplicationJSON)
120120
testBindError(t, strings.NewReader(invalidContent), MIMEApplicationJSON)
121-
testBindSlice(t, strings.NewReader(userJSONArray), MIMEApplicationJSON)
122121
}
123122

124123
func TestBindXML(t *testing.T) {
@@ -141,23 +140,6 @@ func TestBindForm(t *testing.T) {
141140
assert.Error(t, err)
142141
}
143142

144-
func TestBindRouteParam(t *testing.T) {
145-
e := New()
146-
r := strings.NewReader(userJSONOnlyName)
147-
req := httptest.NewRequest(POST, "/", r)
148-
req.Header.Set(HeaderContentType, MIMEApplicationJSON)
149-
rec := httptest.NewRecorder()
150-
c := e.NewContext(req, rec)
151-
c.SetParamNames("id")
152-
c.SetParamValues("5")
153-
u := new(user)
154-
err := c.Bind(u)
155-
if assert.NoError(t, err) {
156-
assert.Equal(t, 5, u.ID)
157-
assert.Equal(t, "Jon Snow", u.Name)
158-
}
159-
}
160-
161143
func TestBindQueryParams(t *testing.T) {
162144
e := New()
163145
req := httptest.NewRequest(GET, "/?id=1&name=Jon+Snow", nil)
@@ -350,19 +332,3 @@ func testBindError(t *testing.T, r io.Reader, ctype string) {
350332
}
351333
}
352334
}
353-
354-
func testBindSlice(t *testing.T, r io.Reader, ctype string) {
355-
e := New()
356-
req := httptest.NewRequest(POST, "/", r)
357-
rec := httptest.NewRecorder()
358-
c := e.NewContext(req, rec)
359-
req.Header.Set(HeaderContentType, ctype)
360-
us := []user{}
361-
err := c.Bind(&us)
362-
if assert.NoError(t, err) {
363-
assert.Equal(t, 1, us[0].ID)
364-
assert.Equal(t, "Jon Snow", us[0].Name)
365-
assert.Equal(t, 2, us[1].ID)
366-
assert.Equal(t, "Arya Stark", us[1].Name)
367-
}
368-
}

echo_test.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,16 @@ import (
1818

1919
type (
2020
user struct {
21-
ID int `json:"id" xml:"id" form:"id" query:"id" param:"id"`
21+
ID int `json:"id" xml:"id" form:"id" query:"id"`
2222
Name string `json:"name" xml:"name" form:"name" query:"name"`
2323
}
2424
)
2525

2626
const (
27-
userJSON = `{"id":1,"name":"Jon Snow"}`
28-
userJSONArray = `[{"id":1,"name":"Jon Snow"},{"id":2,"name":"Arya Stark"}]`
29-
userJSONOnlyName = `{"name":"Jon Snow"}`
30-
userXML = `<user><id>1</id><name>Jon Snow</name></user>`
31-
userForm = `id=1&name=Jon Snow`
32-
invalidContent = "invalid content"
27+
userJSON = `{"id":1,"name":"Jon Snow"}`
28+
userXML = `<user><id>1</id><name>Jon Snow</name></user>`
29+
userForm = `id=1&name=Jon Snow`
30+
invalidContent = "invalid content"
3331
)
3432

3533
const userJSONPretty = `{

0 commit comments

Comments
 (0)