@@ 0,0 1,29 @@
+package gobwebs
+
+import (
+ "log"
+ "sync"
+
+ "github.com/labstack/echo/v4"
+)
+
+// RouteDebugMiddleware prints the route name of a matched path.
+// From: https://github.com/labstack/echo/discussions/2081#discussioncomment-2040098
+func RouteDebugMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
+ var doOnce sync.Once
+ var registeredRoutes []*echo.Route
+
+ return func(c echo.Context) error {
+ doOnce.Do(func() {
+ registeredRoutes = c.Echo().Routes()
+ })
+
+ for _, r := range registeredRoutes {
+ if r.Method == c.Request().Method && r.Path == c.Path() {
+ log.Printf("*** Route Name: %s", r.Name)
+ break
+ }
+ }
+ return next(c)
+ }
+}