- Add surf.Router.AdminPrefix (additive): the admin mount path and true when BuildRouter mounted the cabana admin, false otherwise - serve binds with net.Listen before printing, so a busy port fails without a misleading URL, then prints the listen address with a browser URL and an admin status line: the admin URL, a warning naming summer admin:create when backend_users is empty or missing, or admin: off with the steps to add an admin controller - The administrator count is bounded by a 2 s timeout and never fails boot - route:list ends with the same admin status line - surf and cabana READMEs and the console and routing docs describe the output
40 lines
932 B
Go
40 lines
932 B
Go
package surf
|
|
|
|
// 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
|
|
}
|