Files
proxy/gateway/web/handlers/debug.go

36 lines
759 B
Go
Raw Normal View History

2025-03-08 10:59:31 +08:00
package handlers
import (
"fmt"
2025-05-15 10:04:28 +08:00
"github.com/gofiber/fiber/v2"
"proxy-server/gateway/debug"
2025-03-08 10:59:31 +08:00
"slices"
)
2025-05-15 10:04:28 +08:00
func GetConsuming(c *fiber.Ctx) error {
2025-03-08 10:59:31 +08:00
list := debug.ConsumingList()
// sort by total time
slices.SortFunc(list, func(a debug.Consuming, b debug.Consuming) int {
if a.Total < b.Total {
return 1
} else if a.Total > b.Total {
return -1
}
return 0
})
// map to string
strList := make([]string, len(list))
for i := 0; i < len(list); i++ {
times := list[i]
strList[i] = fmt.Sprintf("Auth: %s, Data: %s, Proxy: %s, Total: %s", times.Auth, times.Data, times.Proxy, times.Total)
}
2025-05-15 10:04:28 +08:00
return c.JSON(strList)
2025-03-08 10:59:31 +08:00
}
2025-05-15 10:04:28 +08:00
func RestConsuming(c *fiber.Ctx) error {
2025-03-08 10:59:31 +08:00
debug.InitConsumingList()
2025-05-15 10:04:28 +08:00
return c.JSON(fiber.Map{
2025-03-08 10:59:31 +08:00
"message": "success",
})
}