瀏覽代碼

merge middleware.Use into router

tags/v0.9.0
jimzhan 9 年之前
父節點
當前提交
7645215bb1
共有 1 個檔案被更改,包括 3 行新增8 行删除
  1. +3
    -8
      router.go

+ 3
- 8
router.go 查看文件

@@ -50,11 +50,6 @@ func (self *middleware) build() http.Handler {
return self.cache
}

// Use add the middleware module into the stack chain.
func (self *middleware) Use(modules ...func(http.Handler) http.Handler) {
self.stack = append(self.stack, modules...)
}

// Implements the net/http Handler interface and calls the middleware stack.
func (self *middleware) ServeHTTP(w http.ResponseWriter, r *http.Request) {
self.build().ServeHTTP(w, r)
@@ -79,13 +74,13 @@ func (self *Router) build() http.Handler {
if !self.ready {
self.ready = true
// * activate router's middleware modules.
self.middleware.Use(func(http.Handler) http.Handler {
self.Use(func(http.Handler) http.Handler {
return self.mux
})
// * activate subrouters's middleware modules.
for index := 0; index < len(self.subrouters); index++ {
sr := self.subrouters[index]
sr.middleware.Use(func(http.Handler) http.Handler {
sr.Use(func(http.Handler) http.Handler {
return sr.mux
})
}
@@ -169,7 +164,7 @@ func (self *Router) Name(r *http.Request) (name string) {

// Use add the middleware module into the stack chain.
func (self *Router) Use(module func(http.Handler) http.Handler) {
self.middleware.Use(module)
self.middleware.stack = append(self.middleware.stack, module)
}

// ServeHTTP dispatches the request to the handler whose

Loading…
取消
儲存