Skip to content

Commit

Permalink
fix(uri): query binding bug (#3236)
Browse files Browse the repository at this point in the history
* fix query mapping

* query binding test
  • Loading branch information
illiafox authored Mar 21, 2024
1 parent 78f4687 commit 8790d08
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions binding/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ func (queryBinding) Name() string {
return "query"
}

func (queryBinding) Bind(req *http.Request, obj any) error {
func (q queryBinding) Bind(req *http.Request, obj any) error {
values := req.URL.Query()
if err := mapForm(obj, values); err != nil {
if err := mapFormByTag(obj, values, q.Name()); err != nil {
return err
}
return validate(obj)
Expand Down
23 changes: 23 additions & 0 deletions binding/query_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package binding

import (
"net/http"
"net/url"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestQueryBinding(t *testing.T) {
var s struct {
Foo string `query:"foo"`
}

request := &http.Request{URL: &url.URL{RawQuery: "foo=BAR"}}

err := queryBinding{}.Bind(request, &s)
require.NoError(t, err)

assert.Equal(t, "BAR", s.Foo)
}

0 comments on commit 8790d08

Please sign in to comment.