initial implementation

This commit is contained in:
juancwu 2026-04-25 20:26:07 +00:00
commit cb373e637b
16 changed files with 777 additions and 1 deletions

19
pkg/router/chain.go Normal file
View 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
}