Last active
September 30, 2015 21:29
-
-
Save dre1080/2778b1c2cf9a82dd7e5c to your computer and use it in GitHub Desktop.
Print Echo registered routes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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