fix(06-14): actually reuse built middleware factories per name:param

The built cache added in 06-12 was declared but never consulted, so every
route re-invoked the factory on BuildRouter and again on compile.
This commit is contained in:
Jakub Zych
2026-09-21 19:47:16 +02:00
parent 54dd60953a
commit 1d2e00cf59

View File

@@ -398,7 +398,12 @@ func (r *Router) wrap(rt route) (http.Handler, error) {
return nil, fmt.Errorf("surf: plugin %q: %w", rt.pluginID, err)
}
}
h = factory.fn(param)(h)
mw, ok := r.built[name]
if !ok {
mw = factory.fn(param)
r.built[name] = mw
}
h = mw(h)
continue
}
}