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.
ims/app/http/routes/print.go

33 lines
611 B

2 months ago
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()
}