Improved route order flexibility

This commit is contained in:
Eduard Urbach 2023-07-10 14:48:28 +02:00
parent 00bab0323b
commit 59c0a95a89
Signed by: eduard
GPG key ID: 49226B848C78F6C8
4 changed files with 99 additions and 5 deletions

View file

@ -1,5 +1,7 @@
package router
import "os"
// Router is a high-performance router.
type Router[T comparable] struct {
get Tree[T]
@ -57,6 +59,12 @@ func (router *Router[T]) Bind(transform func(T) T) {
router.options.Bind(transform)
}
// Print shows a pretty print of all the routes.
func (router *Router[T]) Print(method string) {
tree := router.selectTree(method)
tree.root.PrettyPrint(os.Stdout)
}
// selectTree returns the tree by the given HTTP method.
func (router *Router[T]) selectTree(method string) *Tree[T] {
switch method {