diff --git a/binding/binding.go b/binding/binding.go index 40948529..5663b143 100644 --- a/binding/binding.go +++ b/binding/binding.go @@ -39,9 +39,9 @@ type BindingBody interface { BindBody([]byte, any) error } -// BindingUri adds BindUri method to Binding. BindUri is similar with Bind, +// BindingURI adds BindUri method to Binding. BindUri is similar with Bind, // but it reads the Params. -type BindingUri interface { +type BindingURI interface { Name() string BindUri(map[string][]string, any) error } @@ -81,7 +81,7 @@ var ( ProtoBuf = protobufBinding{} MsgPack = msgpackBinding{} YAML = yamlBinding{} - Uri = uriBinding{} + URI = uriBinding{} Header = headerBinding{} TOML = tomlBinding{} ) diff --git a/binding/binding_test.go b/binding/binding_test.go index 9af4f88a..36048056 100644 --- a/binding/binding_test.go +++ b/binding/binding_test.go @@ -792,7 +792,7 @@ func TestHeaderBinding(t *testing.T) { } func TestUriBinding(t *testing.T) { - b := Uri + b := URI assert.Equal(t, "uri", b.Name()) type Tag struct { @@ -829,7 +829,7 @@ func TestUriInnerBinding(t *testing.T) { } var tag Tag - assert.NoError(t, Uri.BindUri(m, &tag)) + assert.NoError(t, URI.BindUri(m, &tag)) assert.Equal(t, tag.Name, expectedName) assert.Equal(t, tag.S.Age, expectedAge) } diff --git a/context.go b/context.go index 420ff167..1b13702f 100644 --- a/context.go +++ b/context.go @@ -661,10 +661,10 @@ func (c *Context) BindHeader(obj any) error { return c.MustBindWith(obj, binding.Header) } -// BindUri binds the passed struct pointer using binding.Uri. +// BindURI binds the passed struct pointer using binding.Uri. // It will abort the request with HTTP 400 if any error occurs. -func (c *Context) BindUri(obj any) error { - if err := c.ShouldBindUri(obj); err != nil { +func (c *Context) BindURI(obj any) error { + if err := c.ShouldBindURI(obj); err != nil { c.AbortWithError(http.StatusBadRequest, err).SetType(ErrorTypeBind) //nolint: errcheck return err } @@ -726,13 +726,13 @@ func (c *Context) ShouldBindHeader(obj any) error { return c.ShouldBindWith(obj, binding.Header) } -// ShouldBindUri binds the passed struct pointer using the specified binding engine. -func (c *Context) ShouldBindUri(obj any) error { +// ShouldBindURI binds the passed struct pointer using the specified binding engine. +func (c *Context) ShouldBindURI(obj any) error { m := make(map[string][]string) for _, v := range c.Params { m[v.Key] = []string{v.Value} } - return binding.Uri.BindUri(m, obj) + return binding.URI.BindUri(m, obj) } // ShouldBindWith binds the passed struct pointer using the specified binding engine. diff --git a/githubapi_test.go b/githubapi_test.go index 9276bed5..fd595dd9 100644 --- a/githubapi_test.go +++ b/githubapi_test.go @@ -295,7 +295,7 @@ 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.NoError(t, c.ShouldBindURI(&person)) assert.True(t, person.Name != "") assert.True(t, person.ID != "") c.String(http.StatusOK, "ShouldBindUri test OK") @@ -317,7 +317,7 @@ 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.NoError(t, c.BindURI(&person)) assert.True(t, person.Name != "") assert.True(t, person.ID != "") c.String(http.StatusOK, "BindUri test OK") @@ -338,7 +338,7 @@ func TestBindUriError(t *testing.T) { } router.Handle(http.MethodGet, "/new/rest/:num", func(c *Context) { var m Member - assert.Error(t, c.BindUri(&m)) + assert.Error(t, c.BindURI(&m)) }) path1, _ := exampleFromPath("/new/rest/:num")