From 4afad2518921d22d63d77a7a272ca42ff406459d Mon Sep 17 00:00:00 2001 From: Jithin James Date: Mon, 16 Oct 2017 16:25:56 +0530 Subject: [PATCH 1/3] Print all handlers on start-up --- debug.go | 20 ++++++++++++++++++++ doc.go | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/debug.go b/debug.go index 449291e6..55ff5716 100644 --- a/debug.go +++ b/debug.go @@ -6,8 +6,14 @@ package gin import ( "bytes" + "fmt" "html/template" "log" + "os" + "reflect" + "runtime" + + "golang.org/x/crypto/ssh/terminal" ) func init() { @@ -22,7 +28,21 @@ func IsDebugging() bool { func debugPrintRoute(httpMethod, absolutePath string, handlers HandlersChain) { if IsDebugging() { + s := "<<<<<<<\tHandlers Running\t>>>>>>>" + w := 100 + + if terminal.IsTerminal(int(os.Stdout.Fd())) { + w, _, _ = terminal.GetSize(int(os.Stdout.Fd())) + } else { + fmt.Println("Couldn't get terminal size. Using default value...") + } + fmt.Printf(fmt.Sprintf("%%%ds\n", w/2), s) + // fmt.Printf(fmt.Sprintf("%%-%ds", w/2), fmt.Sprintf(fmt.Sprintf("%%%ds\n", w/2), s)) + for i := 0; i < len(handlers); i += 2 { + fmt.Printf(" | %-50s | %-50s |\n", runtime.FuncForPC(reflect.ValueOf(handlers[i]).Pointer()).Name(), runtime.FuncForPC(reflect.ValueOf(handlers[i+1]).Pointer()).Name()) + } nuHandlers := len(handlers) + fmt.Printf("Total %d handlers found...\n", nuHandlers) handlerName := nameOfFunction(handlers.Last()) debugPrint("%-6s %-25s --> %s (%d handlers)\n", httpMethod, absolutePath, handlerName, nuHandlers) } diff --git a/doc.go b/doc.go index 01ac4a90..b555acab 100644 --- a/doc.go +++ b/doc.go @@ -3,4 +3,4 @@ Package gin implements a HTTP web framework called gin. See https://gin-gonic.github.io/gin/ for more information about gin. */ -package gin // import "github.com/gin-gonic/gin" +package gin // import "github.com/jithinjk/gin" From bf55fc85d454cfc0daf772577ab81b53e618e888 Mon Sep 17 00:00:00 2001 From: Jithin James Date: Mon, 16 Oct 2017 16:47:05 +0530 Subject: [PATCH 2/3] List the handlers during start-up --- debug.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/debug.go b/debug.go index 55ff5716..497ad25e 100644 --- a/debug.go +++ b/debug.go @@ -33,16 +33,16 @@ func debugPrintRoute(httpMethod, absolutePath string, handlers HandlersChain) { if terminal.IsTerminal(int(os.Stdout.Fd())) { w, _, _ = terminal.GetSize(int(os.Stdout.Fd())) + w -= 25 } else { - fmt.Println("Couldn't get terminal size. Using default value...") + debugPrint("Couldn't get terminal size. Using default value...\n") } - fmt.Printf(fmt.Sprintf("%%%ds\n", w/2), s) - // fmt.Printf(fmt.Sprintf("%%-%ds", w/2), fmt.Sprintf(fmt.Sprintf("%%%ds\n", w/2), s)) + debugPrint(fmt.Sprintf("%%%ds\n", w/2), s) for i := 0; i < len(handlers); i += 2 { - fmt.Printf(" | %-50s | %-50s |\n", runtime.FuncForPC(reflect.ValueOf(handlers[i]).Pointer()).Name(), runtime.FuncForPC(reflect.ValueOf(handlers[i+1]).Pointer()).Name()) + debugPrint("| %-50s | %-50s |\n", runtime.FuncForPC(reflect.ValueOf(handlers[i]).Pointer()).Name(), runtime.FuncForPC(reflect.ValueOf(handlers[i+1]).Pointer()).Name()) } nuHandlers := len(handlers) - fmt.Printf("Total %d handlers found...\n", nuHandlers) + debugPrint("Total %d handlers found...\n\n", nuHandlers) handlerName := nameOfFunction(handlers.Last()) debugPrint("%-6s %-25s --> %s (%d handlers)\n", httpMethod, absolutePath, handlerName, nuHandlers) } From 1816795d626882b5b328cb404e2473d6fa1a6c4d Mon Sep 17 00:00:00 2001 From: Jithin James Date: Mon, 16 Oct 2017 16:47:05 +0530 Subject: [PATCH 3/3] List the handlers during start-up --- debug.go | 10 +++++----- doc.go | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/debug.go b/debug.go index 55ff5716..497ad25e 100644 --- a/debug.go +++ b/debug.go @@ -33,16 +33,16 @@ func debugPrintRoute(httpMethod, absolutePath string, handlers HandlersChain) { if terminal.IsTerminal(int(os.Stdout.Fd())) { w, _, _ = terminal.GetSize(int(os.Stdout.Fd())) + w -= 25 } else { - fmt.Println("Couldn't get terminal size. Using default value...") + debugPrint("Couldn't get terminal size. Using default value...\n") } - fmt.Printf(fmt.Sprintf("%%%ds\n", w/2), s) - // fmt.Printf(fmt.Sprintf("%%-%ds", w/2), fmt.Sprintf(fmt.Sprintf("%%%ds\n", w/2), s)) + debugPrint(fmt.Sprintf("%%%ds\n", w/2), s) for i := 0; i < len(handlers); i += 2 { - fmt.Printf(" | %-50s | %-50s |\n", runtime.FuncForPC(reflect.ValueOf(handlers[i]).Pointer()).Name(), runtime.FuncForPC(reflect.ValueOf(handlers[i+1]).Pointer()).Name()) + debugPrint("| %-50s | %-50s |\n", runtime.FuncForPC(reflect.ValueOf(handlers[i]).Pointer()).Name(), runtime.FuncForPC(reflect.ValueOf(handlers[i+1]).Pointer()).Name()) } nuHandlers := len(handlers) - fmt.Printf("Total %d handlers found...\n", nuHandlers) + debugPrint("Total %d handlers found...\n\n", nuHandlers) handlerName := nameOfFunction(handlers.Last()) debugPrint("%-6s %-25s --> %s (%d handlers)\n", httpMethod, absolutePath, handlerName, nuHandlers) } diff --git a/doc.go b/doc.go index b555acab..01ac4a90 100644 --- a/doc.go +++ b/doc.go @@ -3,4 +3,4 @@ Package gin implements a HTTP web framework called gin. See https://gin-gonic.github.io/gin/ for more information about gin. */ -package gin // import "github.com/jithinjk/gin" +package gin // import "github.com/gin-gonic/gin"