-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.go
47 lines (41 loc) · 1.14 KB
/
debug.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package debug
import (
"path/filepath"
"sort"
"github.com/gofiber/fiber/v2"
g "github.com/maragudk/gomponents"
c "github.com/maragudk/gomponents/components"
h "github.com/maragudk/gomponents/html"
"github.com/pubgo/lava/core/debug"
)
func init() {
initDebug()
}
func initDebug() {
debug.Get("/", func(ctx *fiber.Ctx) error {
pathMap := make(map[string]interface{})
stack := debug.App().Stack()
for m := range stack {
for r := range stack[m] {
route := stack[m][r]
//if strings.Contains(route.Path, "*") || strings.Contains(route.Path, ":") {
// continue
//}
pathMap[route.Path] = nil
}
}
var pathList []string
for k := range pathMap {
pathList = append(pathList, k)
}
sort.Strings(pathList)
var nodes []g.Node
nodes = append(nodes, h.H1(g.Text("routes")))
for i := range pathList {
path := pathList[i]
nodes = append(nodes, h.A(g.Text(path), g.Attr("href", filepath.Join(string(ctx.Request().Header.Peek("Path-Prefix")), path))), h.Br())
}
ctx.Response().Header.SetContentType(fiber.MIMETextHTMLCharsetUTF8)
return c.HTML5(c.HTML5Props{Title: "/app/routes", Body: nodes}).Render(ctx)
})
}