export pathvar for user-defined routers (#911)

* refactor

* export pathvar for user-defined routers
This commit is contained in:
Kevin Wan
2021-08-14 22:57:28 +08:00
committed by GitHub
parent fbf2eebc42
commit fc04ad7854
6 changed files with 23 additions and 23 deletions

View File

@@ -8,7 +8,7 @@ import (
"github.com/tal-tech/go-zero/core/search"
"github.com/tal-tech/go-zero/rest/httpx"
"github.com/tal-tech/go-zero/rest/internal/context"
"github.com/tal-tech/go-zero/rest/pathvar"
)
const (
@@ -61,7 +61,7 @@ func (pr *patRouter) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if tree, ok := pr.trees[r.Method]; ok {
if result, ok := tree.Search(reqPath); ok {
if len(result.Params) > 0 {
r = context.WithPathVars(r, result.Params)
r = pathvar.WithVars(r, result.Params)
}
result.Item.(http.Handler).ServeHTTP(w, r)
return