Changes Made

- Renamed functions to have more descriptive names.
- Ensured that function names follow golint naming conventions.y
This commit is contained in:
anazibinurasheed 2023-09-13 11:48:01 +05:30
parent c2ba8f19ec
commit aec45eb55b
4 changed files with 14 additions and 14 deletions

View File

@ -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{}
)

View File

@ -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)
}

View File

@ -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.

View File

@ -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")