Skip to content

Commit 2ffb2b4

Browse files
committed
添加item json
1 parent af1d8a5 commit 2ffb2b4

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

http/router/entry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func NewEntrySet() *EntrySet {
1717

1818
// EntrySet 路由条目集
1919
type EntrySet struct {
20-
Items []*Entry
20+
Items []*Entry `json:"items"`
2121
}
2222

2323
// AddEntry 添加Entry

http/router/httprouter/httprouter.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ func (r *httpRouter) addHandler(protected bool, method, path string, h http.Hand
157157

158158
rc := context.GetContext(req)
159159
rc.AuthInfo = authInfo
160+
rc.PS = ps
160161
req = context.WithContext(req, rc)
161162
}
162163

http/router/httprouter/subrouter_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func TestSubRouterTestSuit(t *testing.T) {
1818
t.Run("SetLabel", suit.testSetLabel())
1919
t.Run("AddPublictOK", suit.testAddPublictOK())
2020
t.Run("ResourceRouterOK", suit.testResourceRouterOK())
21+
t.Run("WithParamsOK", suit.testWithParams())
2122
}
2223

2324
func newSubRouterTestSuit(t *testing.T) *subRouterTestSuit {
@@ -79,3 +80,17 @@ func (a *subRouterTestSuit) testResourceRouterOK() func(t *testing.T) {
7980
a.should.Equal(entry.Labels["k1"], "v1")
8081
}
8182
}
83+
84+
func (a *subRouterTestSuit) testWithParams() func(t *testing.T) {
85+
return func(t *testing.T) {
86+
should := assert.New(t)
87+
88+
req, _ := http.NewRequest("GET", "/v1/resources/"+urlParam, nil)
89+
w := httptest.NewRecorder()
90+
91+
a.sub.AddPublict("GET", "/resources/:id", WithContextHandler)
92+
a.root.ServeHTTP(w, req)
93+
94+
should.Equal(200, w.Code)
95+
}
96+
}

0 commit comments

Comments
 (0)