Skip to content

Commit 22cfd33

Browse files
committed
修复 resource base path 问题
1 parent 5831384 commit 22cfd33

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

http/router/httprouter/subrouter.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ func newSubRouter(basePath string, root *httpRouter) *subRouter {
1515
}
1616

1717
type subRouter struct {
18-
basePath string
19-
resourceName string
20-
root *httpRouter
21-
labels []*router.Label
22-
middlewareChain []router.Middleware
18+
basePath string
19+
resourceName string
20+
resourceBasePath string
21+
root *httpRouter
22+
labels []*router.Label
23+
middlewareChain []router.Middleware
2324
}
2425

2526
func (r *subRouter) Use(m router.Middleware) {
@@ -78,15 +79,16 @@ func (r *subRouter) SetLabel(labels ...*router.Label) {
7879

7980
func (r *subRouter) ResourceRouter(resourceName string, labels ...*router.Label) router.ResourceRouter {
8081
return &subRouter{
81-
resourceName: resourceName,
82-
basePath: r.basePath,
83-
root: r.root,
84-
labels: append(r.labels, labels...),
82+
resourceName: resourceName,
83+
resourceBasePath: r.basePath,
84+
basePath: r.basePath,
85+
root: r.root,
86+
labels: append(r.labels, labels...),
8587
}
8688
}
8789

8890
func (r *subRouter) BasePath(path string) {
89-
r.basePath += "/" + path
91+
r.basePath = r.resourceBasePath + "/" + path
9092
}
9193

9294
func (r *subRouter) add(e *entry) {

0 commit comments

Comments
 (0)