添加在线调试 api
This commit is contained in:
36
server/web/handlers/debug.go
Normal file
36
server/web/handlers/debug.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"proxy-server/server/debug"
|
||||
"slices"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func GetConsuming(c *gin.Context) {
|
||||
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)
|
||||
}
|
||||
c.JSON(200, strList)
|
||||
}
|
||||
|
||||
func RestConsuming(c *gin.Context) {
|
||||
debug.InitConsumingList()
|
||||
c.JSON(200, gin.H{
|
||||
"message": "success",
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user