Files
summercms/modules/surf/routetable.go
Jakub Zych 1bd91a4522 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
2026-10-22 16:00:19 +02:00

56 lines
1.6 KiB
Go

package surf
import "net/http"
// RouteInfo is a read-only snapshot of one registered route after Assemble
// or BuildRouter.
type RouteInfo struct {
Method string
Pattern string
PluginID string
Middleware []string
Raw bool
}
// AdminPrefix reports the cabana admin mount path set by BuildRouter. False
// means no plugin registers an admin controller, so no admin routes exist.
func (r *Router) AdminPrefix() (string, bool) {
if r == nil || !r.adminMounted {
return "", false
}
return r.adminPrefix, true
}
// Routes returns a defensive copy of every registered route.
func (r *Router) Routes() []RouteInfo {
if r == nil {
return nil
}
out := make([]RouteInfo, len(r.routes))
for i, rt := range r.routes {
mw := append([]string{}, rt.middleware...)
out[i] = RouteInfo{
Method: rt.method,
Pattern: rt.path,
PluginID: rt.pluginID,
Middleware: mw,
Raw: rt.raw,
}
}
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
}