Skip to content

Commit 3da4b50

Browse files
committed
auther 仅支持entry
1 parent df6e8f8 commit 3da4b50

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

http/router/httprouter/httprouter.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,17 @@ func (r *httpRouter) add(e *entry) {
136136
r.addEntry(e)
137137
}
138138

139+
// 在添加路由时 装饰了认证逻辑
139140
func (r *httpRouter) addHandler(protected bool, method, path string, h http.Handler) {
140141
wrapper := func(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
141-
entry := r.findEntry(method, path)
142-
if entry == nil {
143-
r.notFound.ServeHTTP(w, req)
144-
return
145-
}
146142
// 使用auther进行认证
147143
if protected && r.auther != nil {
144+
entry := r.findEntry(method, path)
145+
if entry == nil {
146+
r.notFound.ServeHTTP(w, req)
147+
return
148+
}
149+
148150
authInfo, err := r.auther.Auth(req.Header, *entry.Entry)
149151
if err != nil {
150152
response.Failed(w, err)
@@ -167,7 +169,6 @@ func (r *httpRouter) addHandler(protected bool, method, path string, h http.Hand
167169

168170
h.ServeHTTP(w, req)
169171
}
170-
171172
r.r.Handle(method, path, wrapper)
172173
}
173174

0 commit comments

Comments
 (0)