Skip to content
Myr

feat: add go version judge when print debug warning log (#1572)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* feat: add go version judge when print debug warning log * remove invalid statement * use one const

authored by 田欧 · committed by GitHub · parent fd599fc · Browse files · 2 files+40 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+40 added−2 removed

  • other:+40 added−2 removed

2 files+40 added−2 removed

modified:debug_test.go+23 added-1 removed
9 unmodified lines
10 "html/template"11 "io"12 "log"13 "os"14 "runtime"15 "sync"16 "testing"1718 "github.com/stretchr/testify/assert"
69 unmodified lines
88 SetMode(DebugMode)89 debugPrintWARNINGDefault()90 SetMode(TestMode)91 })92 m, e := getMinVer(runtime.Version())93 assert.Nil(t, e)94 if m <= ginSupportMinGoVer {91 assert.Equal(t, "[GIN-debug] [WARNING] Now Gin requires Go 1.6 or later and Go 1.7 will be required soon.\n\n[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.\n\n", re)95 assert.Equal(t, "[GIN-debug] [WARNING] Now Gin requires Go 1.6 or later and Go 1.7 will be required soon.\n\n[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.\n\n", re)96 } else {97 assert.Equal(t, "[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.\n\n", re)98 }99}100101func TestDebugPrintWARNINGNew(t *testing.T) {102 re := captureOutput(func() {
32 unmodified lines
135 f()136 writer.Close()137 return <-out138}139140func TestGetMinVer(t *testing.T) {141 var m uint64142 var e error143 _, e = getMinVer("go1")144 assert.NotNil(t, e)145 m, e = getMinVer("go1.1")146 assert.Equal(t, uint64(1), m)147 assert.Nil(t, e)148 m, e = getMinVer("go1.1.1")149 assert.Nil(t, e)150 assert.Equal(t, uint64(1), m)151 _, e = getMinVer("go1.1.1.1")152 assert.NotNil(t, e)153}
modified:debug.go+17 added-1 removed
6 unmodified lines
7import (8 "bytes"9 "fmt"10 "html/template"11 "runtime"12 "strconv"13 "strings"14)1516const ginSupportMinGoVer = 61718// IsDebugging returns true if the framework is running in debug mode.19// Use SetMode(gin.ReleaseMode) to disable debug mode.20func IsDebugging() bool {21 return ginMode == debugCode
31 unmodified lines
53 fmt.Printf("[GIN-debug] "+format, values...)54 }55}5657func getMinVer(v string) (uint64, error) {58 first := strings.IndexByte(v, '.')59 last := strings.LastIndexByte(v, '.')60 if first == last {61 return strconv.ParseUint(v[first+1:], 10, 64)62 }63 return strconv.ParseUint(v[first+1:last], 10, 64)64}6566func debugPrintWARNINGDefault() {67 if v, e := getMinVer(runtime.Version()); e == nil && v <= ginSupportMinGoVer {53 debugPrint(`[WARNING] Now Gin requires Go 1.6 or later and Go 1.7 will be required soon.68 debugPrint(`[WARNING] Now Gin requires Go 1.6 or later and Go 1.7 will be required soon.6970`)71 }72 debugPrint(`[WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.7374`)75}
24 unmodified lines