Skip to content
Myr

debug.go

This file

Path

debug.go

114 lines · 2.9 KiB · Go

Last changed by

ci: update Go version support to 1.25+ across CI and docs (#4550)Bo-Yi Wubefore adoptionae3f524

History of this file

Take it

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

chore(deps): bump github.com/pelletier/go-toml/v2 from 2.2.2 to 2.2.4 (#4212)dependabot[bot]before adoptioncf32d2d

lines 1–15why, one step back
1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style3// license that can be found in the LICENSE file.45package gin67import (8 "fmt"9 "html/template"10 "runtime"11 "strconv"12 "strings"13 "sync/atomic"14)15

ci: update Go version support to 1.25+ across CI and docs (#4550)Bo-Yi Wubefore adoptionae3f524

line 16why, one step back
16const ginSupportMinGoVer = 25

chore(deps): bump github.com/pelletier/go-toml/v2 from 2.2.2 to 2.2.4 (#4212)dependabot[bot]before adoptioncf32d2d

line 17why, one step back
17

test(debug): improve the test coverage of debug.go to 100% (#4404)OHZEKI Naokibefore adoption19b877f

lines 18–19why, one step back
18var runtimeVersion = runtime.Version()
19

chore(deps): bump github.com/pelletier/go-toml/v2 from 2.2.2 to 2.2.4 (#4212)dependabot[bot]before adoptioncf32d2d

lines 20–29why, one step back
20// IsDebugging returns true if the framework is running in debug mode.
21// Use SetMode(gin.ReleaseMode) to disable debug mode.22func IsDebugging() bool {23 return atomic.LoadInt32(&ginMode) == debugCode24}2526// DebugPrintRouteFunc indicates debug log output format.27var DebugPrintRouteFunc func(httpMethod, absolutePath, handlerName string, nuHandlers int)2829// DebugPrintFunc indicates debug log output format.

refactor: replace interface{} with any in type declarations (#4249)Flc゛before adoption848e1cd

line 30why, one step back
30var DebugPrintFunc func(format string, values ...any)

chore(deps): bump github.com/pelletier/go-toml/v2 from 2.2.2 to 2.2.4 (#4212)dependabot[bot]before adoptioncf32d2d

lines 31–81why, one step back
31
32func debugPrintRoute(httpMethod, absolutePath string, handlers HandlersChain) {33 if IsDebugging() {34 nuHandlers := len(handlers)35 handlerName := nameOfFunction(handlers.Last())36 if DebugPrintRouteFunc == nil {37 debugPrint("%-6s %-25s --> %s (%d handlers)\n", httpMethod, absolutePath, handlerName, nuHandlers)38 } else {39 DebugPrintRouteFunc(httpMethod, absolutePath, handlerName, nuHandlers)40 }41 }42}4344func debugPrintLoadTemplate(tmpl *template.Template) {45 if IsDebugging() {46 var buf strings.Builder47 for _, tmpl := range tmpl.Templates() {48 buf.WriteString("\t- ")49 buf.WriteString(tmpl.Name())50 buf.WriteString("\n")51 }52 debugPrint("Loaded HTML Templates (%d): \n%s\n", len(tmpl.Templates()), buf.String())53 }54}5556func debugPrint(format string, values ...any) {57 if !IsDebugging() {58 return59 }6061 if DebugPrintFunc != nil {62 DebugPrintFunc(format, values...)63 return64 }6566 if !strings.HasSuffix(format, "\n") {67 format += "\n"68 }69 fmt.Fprintf(DefaultWriter, "[GIN-debug] "+format, values...)70}7172func getMinVer(v string) (uint64, error) {73 first := strings.IndexByte(v, '.')74 last := strings.LastIndexByte(v, '.')75 if first == last {76 return strconv.ParseUint(v[first+1:], 10, 64)77 }78 return strconv.ParseUint(v[first+1:last], 10, 64)79}8081func debugPrintWARNINGDefault() {

test(debug): improve the test coverage of debug.go to 100% (#4404)OHZEKI Naokibefore adoption19b877f

line 82why, one step back
82 if v, e := getMinVer(runtimeVersion); e == nil && v < ginSupportMinGoVer {

ci: update Go version support to 1.25+ across CI and docs (#4550)Bo-Yi Wubefore adoptionae3f524

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

chore(deps): bump github.com/pelletier/go-toml/v2 from 2.2.2 to 2.2.4 (#4212)dependabot[bot]before adoptioncf32d2d

lines 84–114why, one step back
84
85`)86 }87 debugPrint(`[WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.8889`)90}9192func debugPrintWARNINGNew() {93 debugPrint(`[WARNING] Running in "debug" mode. Switch to "release" mode in production.94 - using env: export GIN_MODE=release95 - using code: gin.SetMode(gin.ReleaseMode)9697`)98}99100func debugPrintWARNINGSetHTMLTemplate() {101 debugPrint(`[WARNING] Since SetHTMLTemplate() is NOT thread-safe. It should only be called102at initialization. ie. before any route is registered or the router is listening in a socket:103104 router := gin.Default()105 router.SetHTMLTemplate(template) // << good place106107`)108}109110func debugPrintError(err error) {111 if err != nil && IsDebugging() {112 fmt.Fprintf(DefaultErrorWriter, "[GIN-debug] [ERROR] %v\n", err)113 }114}