Browse Source

finalize middleware module structure

tags/v0.9.0
jimzhan 9 years ago
parent
commit
8813d0b8bb
1 changed files with 9 additions and 5 deletions
  1. +9
    -5
      module.go

+ 9
- 5
module.go View File

@@ -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…
Cancel
Save