From 3be3a8186535700ff748fd46f4bafd8673bd53aa Mon Sep 17 00:00:00 2001 From: Tit Petric Date: Tue, 10 Jul 2018 16:02:11 +0200 Subject: [PATCH] print debug routes --- crm/routes.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crm/routes.go b/crm/routes.go index 43fe272ce..97ed32154 100644 --- a/crm/routes.go +++ b/crm/routes.go @@ -16,6 +16,7 @@ package crm */ import ( + "fmt" "github.com/go-chi/chi" ) @@ -33,4 +34,18 @@ func MountRoutes(r chi.Router) { r.Get("/list", types.List) r.Get("/type/{id}", types.Type) }) + + var printRoutes func(chi.Routes) + printRoutes = func(r chi.Routes) { + routes := r.Routes() + for _, route := range routes { + if len(route.SubRoutes.Routes()) > 0 { + fmt.Printf("%s - with %d handlers, %d subroutes", route.Pattern, len(route.Handlers), len(route.SubRoutes.Routes())) + printRoutes(route.SubRoutes) + } else { + fmt.Printf("%s - with %d handlers\n", route.Pattern, len(route.Handlers)) + } + } + } + printRoutes(r) }