Skip to content
Myr

debug.go

This file

Path

debug.go

101 lines · 2.7 KiB · Go

Last changed by

chore: support min go version 1.18 (#3511)thinkeroubefore adoption1e1f0b1

History of this file

Take it

The walk stopped after 200 commits: lines older than a550c56 point at it.

chore: update go.mod and remove space from copyright (#3158)thinkeroubefore adoption4b68a5f

line 1why, one step back
1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.

chore: Add go1.17 for testing (#2828)Bo-Yi Wubefore adoptiona550c56

lines 2–14why, one step back
2// Use of this source code is governed by a MIT style
3// license that can be found in the LICENSE file.45package gin67import (8 "fmt"9 "html/template"10 "runtime"11 "strconv"12 "strings"13)14

chore: support min go version 1.18 (#3511)thinkeroubefore adoption1e1f0b1

line 15why, one step back
15const ginSupportMinGoVer = 18

chore: Add go1.17 for testing (#2828)Bo-Yi Wubefore adoptiona550c56

lines 16–49why, one step back
16
17// IsDebugging returns true if the framework is running in debug mode.18// Use SetMode(gin.ReleaseMode) to disable debug mode.19func IsDebugging() bool {20 return ginMode == debugCode21}2223// DebugPrintRouteFunc indicates debug log output format.24var DebugPrintRouteFunc func(httpMethod, absolutePath, handlerName string, nuHandlers int)2526func debugPrintRoute(httpMethod, absolutePath string, handlers HandlersChain) {27 if IsDebugging() {28 nuHandlers := len(handlers)29 handlerName := nameOfFunction(handlers.Last())30 if DebugPrintRouteFunc == nil {31 debugPrint("%-6s %-25s --> %s (%d handlers)\n", httpMethod, absolutePath, handlerName, nuHandlers)32 } else {33 DebugPrintRouteFunc(httpMethod, absolutePath, handlerName, nuHandlers)34 }35 }36}3738func debugPrintLoadTemplate(tmpl *template.Template) {39 if IsDebugging() {40 var buf strings.Builder41 for _, tmpl := range tmpl.Templates() {42 buf.WriteString("\t- ")43 buf.WriteString(tmpl.Name())44 buf.WriteString("\n")45 }46 debugPrint("Loaded HTML Templates (%d): \n%s\n", len(tmpl.Templates()), buf.String())47 }48}49

test support go1.18 (#2990)thinkeroubefore adoption2bde107

line 50why, one step back
50func debugPrint(format string, values ...any) {

chore: Add go1.17 for testing (#2828)Bo-Yi Wubefore adoptiona550c56

lines 51–68why, one step back
51 if IsDebugging() {
52 if !strings.HasSuffix(format, "\n") {53 format += "\n"54 }55 fmt.Fprintf(DefaultWriter, "[GIN-debug] "+format, values...)56 }57}5859func getMinVer(v string) (uint64, error) {60 first := strings.IndexByte(v, '.')61 last := strings.LastIndexByte(v, '.')62 if first == last {63 return strconv.ParseUint(v[first+1:], 10, 64)64 }65 return strconv.ParseUint(v[first+1:last], 10, 64)66}6768func debugPrintWARNINGDefault() {

Fix the value of ginSupportMinGoVer constant by semantic (#3221)mstmdevbefore adoption088cdd7

line 69why, one step back
69 if v, e := getMinVer(runtime.Version()); e == nil && v < ginSupportMinGoVer {

chore: support min go version 1.18 (#3511)thinkeroubefore adoption1e1f0b1

line 70why, one step back
70 debugPrint(`[WARNING] Now Gin requires Go 1.18+.

chore: Add go1.17 for testing (#2828)Bo-Yi Wubefore adoptiona550c56

lines 71–101why, one step back
71
72`)73 }74 debugPrint(`[WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.7576`)77}7879func debugPrintWARNINGNew() {80 debugPrint(`[WARNING] Running in "debug" mode. Switch to "release" mode in production.81 - using env: export GIN_MODE=release82 - using code: gin.SetMode(gin.ReleaseMode)8384`)85}8687func debugPrintWARNINGSetHTMLTemplate() {88 debugPrint(`[WARNING] Since SetHTMLTemplate() is NOT thread-safe. It should only be called89at initialization. ie. before any route is registered or the router is listening in a socket:9091 router := gin.Default()92 router.SetHTMLTemplate(template) // << good place9394`)95}9697func debugPrintError(err error) {98 if err != nil && IsDebugging() {99 fmt.Fprintf(DefaultErrorWriter, "[GIN-debug] [ERROR] %v\n", err)100 }101}