You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
611 B
32 lines
611 B
package routes
|
|
|
|
import (
|
|
"os"
|
|
"reflect"
|
|
"runtime"
|
|
"strings"
|
|
|
|
"github.com/olekukonko/tablewriter"
|
|
"zestack.dev/slim"
|
|
)
|
|
|
|
func printRoutes(router slim.Router) {
|
|
table := tablewriter.NewWriter(os.Stdout)
|
|
table.SetHeader([]string{"Method", "Pattern", "Name", "Handler"})
|
|
table.SetHeaderAlignment(3)
|
|
|
|
for _, route := range router.Routes() {
|
|
table.Append([]string{
|
|
strings.Join(route.Methods(), ","),
|
|
route.Pattern(),
|
|
route.Name(),
|
|
nameOfFunction(route.Handler()),
|
|
})
|
|
}
|
|
|
|
table.Render()
|
|
}
|
|
|
|
func nameOfFunction(f any) string {
|
|
return runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name()
|
|
}
|
|
|