Skip to content

Commit

Permalink
binds the param string to a struct use params tag (gofiber#1968)
Browse files Browse the repository at this point in the history
* add: params parse

* fix: binds the param string to a struct use params tag
  • Loading branch information
xjellyx authored and trim21 committed Aug 15, 2022
1 parent 0a698b9 commit 8587993
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions ctx.go
Expand Up @@ -39,7 +39,7 @@ const (
queryTag = "query"
reqHeaderTag = "reqHeader"
bodyTag = "form"
uriTag = "uri"
paramsTag = "params"
)

// userContextKey define the key name for storing context.Context in *fasthttp.RequestCtx
Expand Down Expand Up @@ -861,7 +861,7 @@ func (c *Ctx) ParamsParser(out interface{}) error {
for _, param := range c.route.Params {
params[param] = append(params[param], c.Params(param))
}
return c.parseToStruct(uriTag, out, params)
return c.parseToStruct(paramsTag, out, params)
}

// ParamsInt is used to get an integer from the route parameters
Expand Down
12 changes: 6 additions & 6 deletions ctx_test.go
Expand Up @@ -431,8 +431,8 @@ func Test_Ctx_ParamParser(t *testing.T) {
app := New()
app.Get("/test1/userId/role/:roleId", func(ctx *Ctx) error {
type Demo struct {
UserID uint `uri:"userId"`
RoleID uint `uri:"roleId"`
UserID uint `params:"userId"`
RoleID uint `params:"roleId"`
}
var (
d = new(Demo)
Expand Down Expand Up @@ -1470,10 +1470,10 @@ func Benchmark_Ctx_ParamsParse(b *testing.B) {
"john", "doe", "is", "awesome",
}
var res struct {
Param1 string `uri:"param1"`
Param2 string `uri:"param2"`
Param3 string `uri:"param3"`
Param4 string `uri:"param4"`
Param1 string `params:"param1"`
Param2 string `params:"param2"`
Param3 string `params:"param3"`
Param4 string `params:"param4"`
}
b.ReportAllocs()
b.ResetTimer()
Expand Down

0 comments on commit 8587993

Please sign in to comment.