Skip to content

Instantly share code, notes, and snippets.

@dre1080
Last active September 30, 2015 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dre1080/2778b1c2cf9a82dd7e5c to your computer and use it in GitHub Desktop.
Save dre1080/2778b1c2cf9a82dd7e5c to your computer and use it in GitHub Desktop.
Print Echo registered routes
package util
import (
"log"
"strings"
"github.com/labstack/echo"
)
// DebugPrintRoutes prints all registered routes of e.
func DebugPrintRoutes(e *echo.Echo) {
log.Printf("\n\nRegistered routes:\n%s\n", strings.Repeat("-", 18))
routes := e.Routes()
for _, route := range routes {
log.Printf("%-5s %-35s --> %s", route.Method, route.Path, stripPackage(route.Handler.(string)))
}
}
func stripPackage(n string) string {
slashI := strings.LastIndex(n, "/")
if slashI == -1 {
slashI = 0 // for built-in packages
}
return n[slashI+1:]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment