initial implementation
This commit is contained in:
parent
f8b0abc517
commit
cb373e637b
16 changed files with 777 additions and 1 deletions
19
pkg/router/chain.go
Normal file
19
pkg/router/chain.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package router
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.juancwu.dev/juancwu/lightmux/pkg/middleware"
|
||||
)
|
||||
|
||||
// chain wraps h with groupMws followed by routeMws so that groupMws[0] is the
|
||||
// outermost layer (runs first on request, last on response).
|
||||
func chain(h http.Handler, groupMws, routeMws []middleware.Middleware) http.Handler {
|
||||
all := make([]middleware.Middleware, 0, len(groupMws)+len(routeMws))
|
||||
all = append(all, groupMws...)
|
||||
all = append(all, routeMws...)
|
||||
for i := len(all) - 1; i >= 0; i-- {
|
||||
h = all[i](h)
|
||||
}
|
||||
return h
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue