mirror of https://github.com/gin-gonic/gin.git
Merge branch 'gin-gonic:master' into options
This commit is contained in:
commit
e4c05ffa85
|
@ -12,9 +12,9 @@ func (queryBinding) Name() string {
|
||||||
return "query"
|
return "query"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q queryBinding) Bind(req *http.Request, obj any) error {
|
func (queryBinding) Bind(req *http.Request, obj any) error {
|
||||||
values := req.URL.Query()
|
values := req.URL.Query()
|
||||||
if err := mapFormByTag(obj, values, q.Name()); err != nil {
|
if err := mapForm(obj, values); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return validate(obj)
|
return validate(obj)
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
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)
|
|
||||||
}
|
|
Loading…
Reference in New Issue