瀏覽代碼

finalize middleware module structure

tags/v0.9.0
jimzhan 9 年之前
父節點
當前提交
8813d0b8bb
共有 1 個文件被更改,包括 9 次插入5 次删除
  1. +9
    -5
      module.go

+ 9
- 5
module.go 查看文件

@@ -25,17 +25,21 @@ package rex
import "net/http"

type module struct {
cache http.Handler
stack []func(http.Handler) http.Handler
}

// build sets up the whole middleware modules in a FIFO chain.
func (self *module) build() http.Handler {
var next http.Handler = http.DefaultServeMux
// Activate modules in FIFO order.
for index := len(self.stack) - 1; index >= 0; index-- {
next = self.stack[index](next)
if self.cache == nil {
var next http.Handler = http.DefaultServeMux
// Activate modules in FIFO order.
for index := len(self.stack) - 1; index >= 0; index-- {
next = self.stack[index](next)
}
self.cache = next
}
return next
return self.cache
}

// Use add the middleware module into the stack chain.

Loading…
取消
儲存