-
Notifications
You must be signed in to change notification settings - Fork 2
/
debug.go
37 lines (30 loc) · 944 Bytes
/
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
package fox
import (
"fmt"
"strings"
"github.com/gin-gonic/gin"
"github.com/fox-gonic/fox/utils"
)
func init() {
gin.DebugPrintRouteFunc = func(httpMethod, absolutePath, handlerName string, nuHandlers int) {}
}
// IsDebugging returns true if the framework is running in debug mode.
// Use SetMode(gin.ReleaseMode) to disable debug mode.
func IsDebugging() bool {
return foxMode == DebugMode
}
func debugPrintRoute(group *RouterGroup, httpMethod, absolutePath string, handlers HandlersChain) {
if IsDebugging() {
nuHandlers := len(group.router.Handlers) + len(handlers)
handlerName := utils.NameOfFunction(handlers.Last())
debugPrint("%-6s %-25s --> %s (%d handlers)\n", httpMethod, absolutePath, handlerName, nuHandlers)
}
}
func debugPrint(format string, values ...any) {
if IsDebugging() {
if !strings.HasSuffix(format, "\n") {
format += "\n"
}
fmt.Fprintf(DefaultWriter, "[FOX-debug] "+format, values...)
}
}