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:
@@ -398,7 +398,12 @@ func (r *Router) wrap(rt route) (http.Handler, error) {
|
|||||||
return nil, fmt.Errorf("surf: plugin %q: %w", rt.pluginID, err)
|
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
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user