mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-24 02:32:17 +08:00
Merge fff79fa8dcc5b3d4525bacf0bf66d6e7c162132b into b8b68314faa067acae5b17c828127b04af51ebe2
This commit is contained in:
commit
562957184c
20
debug.go
20
debug.go
@ -6,8 +6,14 @@ package gin
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
|
"reflect"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
|
"golang.org/x/crypto/ssh/terminal"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -22,7 +28,21 @@ func IsDebugging() bool {
|
|||||||
|
|
||||||
func debugPrintRoute(httpMethod, absolutePath string, handlers HandlersChain) {
|
func debugPrintRoute(httpMethod, absolutePath string, handlers HandlersChain) {
|
||||||
if IsDebugging() {
|
if IsDebugging() {
|
||||||
|
s := "<<<<<<<\tHandlers Running\t>>>>>>>"
|
||||||
|
w := 100
|
||||||
|
|
||||||
|
if terminal.IsTerminal(int(os.Stdout.Fd())) {
|
||||||
|
w, _, _ = terminal.GetSize(int(os.Stdout.Fd()))
|
||||||
|
w -= 25
|
||||||
|
} else {
|
||||||
|
debugPrint("Couldn't get terminal size. Using default value...\n")
|
||||||
|
}
|
||||||
|
debugPrint(fmt.Sprintf("%%%ds\n", w/2), s)
|
||||||
|
for i := 0; i < len(handlers); i += 2 {
|
||||||
|
debugPrint("| %-50s | %-50s |\n", runtime.FuncForPC(reflect.ValueOf(handlers[i]).Pointer()).Name(), runtime.FuncForPC(reflect.ValueOf(handlers[i+1]).Pointer()).Name())
|
||||||
|
}
|
||||||
nuHandlers := len(handlers)
|
nuHandlers := len(handlers)
|
||||||
|
debugPrint("Total %d handlers found...\n\n", nuHandlers)
|
||||||
handlerName := nameOfFunction(handlers.Last())
|
handlerName := nameOfFunction(handlers.Last())
|
||||||
debugPrint("%-6s %-25s --> %s (%d handlers)\n", httpMethod, absolutePath, handlerName, nuHandlers)
|
debugPrint("%-6s %-25s --> %s (%d handlers)\n", httpMethod, absolutePath, handlerName, nuHandlers)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user