浏览代码

finalize middleware module structure

tags/v0.9.0
jimzhan 10 年前
父节点
当前提交
8813d0b8bb
共有 1 个文件被更改,包括 9 次插入5 次删除
  1. +9
    -5
      module.go

+ 9
- 5
module.go 查看文件

import "net/http" import "net/http"


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


// build sets up the whole middleware modules in a FIFO chain. // build sets up the whole middleware modules in a FIFO chain.
func (self *module) build() http.Handler { 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. // Use add the middleware module into the stack chain.

正在加载...
取消
保存