- 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
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package surf
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"git.golem15.com/golem15/summercms/modules/backpack"
|
|
"git.golem15.com/golem15/summercms/modules/bonfire"
|
|
"git.golem15.com/golem15/summercms/modules/party"
|
|
)
|
|
|
|
// RouteListCommand builds the router the same way ServeCommand does, then
|
|
// renders Routes() as a table instead of serving, followed by the admin
|
|
// status line.
|
|
func RouteListCommand(app *backpack.App, plugins []party.Plugin) bonfire.Command {
|
|
return bonfire.Command{
|
|
Name: "route:list",
|
|
Description: "List registered HTTP routes",
|
|
Run: func(ctx context.Context, in bonfire.Input, out bonfire.Output) error {
|
|
r, err := BuildRouter(app, plugins)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
infos := r.Routes()
|
|
rows := make([][]string, 0, len(infos))
|
|
for _, rt := range infos {
|
|
rows = append(rows, []string{
|
|
rt.Method,
|
|
rt.Pattern,
|
|
rt.PluginID,
|
|
strings.Join(rt.Middleware, ","),
|
|
strconv.FormatBool(rt.Raw),
|
|
})
|
|
}
|
|
out.Table([]string{"Method", "Pattern", "Plugin", "Middleware", "Raw"}, rows)
|
|
if prefix, mounted := r.AdminPrefix(); mounted {
|
|
out.Info("admin: mounted at " + prefix)
|
|
} else {
|
|
out.Info(adminOffText)
|
|
}
|
|
return nil
|
|
},
|
|
}
|
|
}
|