Skip to content

Commit 4085c9b

Browse files
committed
修复资源事件
1 parent 66549b0 commit 4085c9b

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

http/router/httprouter/httprouter.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,17 @@ func (r *httpRouter) addHandler(method, path string, h http.Handler) {
144144
authInfo interface{}
145145
entry *entry
146146
)
147-
if r.auther != nil {
148-
entry = r.findEntry(method, path)
149-
if entry == nil {
150-
r.notFound.ServeHTTP(w, req)
151-
return
152-
}
153-
rc.Entry = entry.Entry
154147

148+
// 路由匹配
149+
entry = r.findEntry(method, path)
150+
if entry == nil {
151+
r.notFound.ServeHTTP(w, req)
152+
return
153+
}
154+
rc.Entry = entry.Entry
155+
156+
// 认证
157+
if r.auther != nil {
155158
ai, err := r.auther.Auth(req, *entry.Entry)
156159
if err != nil {
157160
response.Failed(w, err)

http/router/httprouter/httprouter_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ func WithContextHandler(w http.ResponseWriter, r *http.Request) {
3434
return
3535
}
3636

37-
if rctx.Entry == nil {
38-
response.Failed(w, exception.NewBadRequest("no entry"))
39-
}
40-
4137
response.Failed(w, exception.NewBadRequest("failed"))
4238
return
4339
}
@@ -47,6 +43,7 @@ func ResourceEventHandler(w http.ResponseWriter, r *http.Request) {
4743

4844
if rctx.Entry == nil {
4945
response.Failed(w, exception.NewBadRequest("no entry"))
46+
return
5047
}
5148

5249
data := &mockResourceEvent{entry: rctx.Entry}

0 commit comments

Comments
 (0)