feat(19.7-01): in-process dispatch marker and compiled handler lookup

- bouncer.Dispatch, WithDispatch, Dispatched: context-only pre-resolved
  principal marker honoured by Registry.Middleware for listed guard names
- cabana.ResolveBackend honours a backend-kind marker; additive
  ResolveBackendToken, ScopeLimitFor and BackendPrincipal resolvers
- surf.Router.Handler and compileHandlers: one compiled chain per route,
  shared by BuildRouter validation and compile
- smoke tests TestDispatchSmoke, TestDispatchedSmoke, TestDispatchMarkerSmoke
- READMEs and docs/services/{authentication,routing}.md updated
This commit is contained in:
Jakub Zych
2026-10-22 16:00:19 +02:00
parent a74a218cd9
commit 1bd91a4522
14 changed files with 522 additions and 11 deletions

View File

@@ -1,5 +1,7 @@
package surf
import "net/http"
// RouteInfo is a read-only snapshot of one registered route after Assemble
// or BuildRouter.
type RouteInfo struct {
@@ -37,3 +39,17 @@ func (r *Router) Routes() []RouteInfo {
}
return out
}
// Handler returns the compiled middleware chain of the route registered for
// method and pattern (as listed by Routes), for an in-process dispatch that
// must run the same constraints, guards, throttles, body limit, locale and
// recovery as an HTTP request. The caller sets the path values and Pattern
// on its request before serving, as the mux would. False when no such route
// exists or BuildRouter has not compiled the routes yet.
func (r *Router) Handler(method, pattern string) (http.Handler, bool) {
if r == nil || r.handlers == nil {
return nil, false
}
h, ok := r.handlers[method+" "+pattern]
return h, ok && h != nil
}