mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-21 16:58:08 +08:00
Replace bytes.Buffer to strings.Builder
This commit is contained in:
parent
73c4633943
commit
792b670ea3
14
debug.go
14
debug.go
@ -5,15 +5,15 @@
|
|||||||
package gin
|
package gin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const ginSupportMinGoVer = 8
|
const ginSupportMinGoVer = 6
|
||||||
|
|
||||||
// IsDebugging returns true if the framework is running in debug mode.
|
// IsDebugging returns true if the framework is running in debug mode.
|
||||||
// Use SetMode(gin.ReleaseMode) to disable debug mode.
|
// Use SetMode(gin.ReleaseMode) to disable debug mode.
|
||||||
@ -38,7 +38,7 @@ func debugPrintRoute(httpMethod, absolutePath string, handlers HandlersChain) {
|
|||||||
|
|
||||||
func debugPrintLoadTemplate(tmpl *template.Template) {
|
func debugPrintLoadTemplate(tmpl *template.Template) {
|
||||||
if IsDebugging() {
|
if IsDebugging() {
|
||||||
var buf bytes.Buffer
|
var buf strings.Builder
|
||||||
for _, tmpl := range tmpl.Templates() {
|
for _, tmpl := range tmpl.Templates() {
|
||||||
buf.WriteString("\t- ")
|
buf.WriteString("\t- ")
|
||||||
buf.WriteString(tmpl.Name())
|
buf.WriteString(tmpl.Name())
|
||||||
@ -53,7 +53,7 @@ func debugPrint(format string, values ...interface{}) {
|
|||||||
if !strings.HasSuffix(format, "\n") {
|
if !strings.HasSuffix(format, "\n") {
|
||||||
format += "\n"
|
format += "\n"
|
||||||
}
|
}
|
||||||
fmt.Fprintf(DefaultWriter, "[GIN-debug] "+format, values...)
|
fmt.Fprintf(os.Stderr, "[GIN-debug] "+format, values...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ func getMinVer(v string) (uint64, error) {
|
|||||||
|
|
||||||
func debugPrintWARNINGDefault() {
|
func debugPrintWARNINGDefault() {
|
||||||
if v, e := getMinVer(runtime.Version()); e == nil && v <= ginSupportMinGoVer {
|
if v, e := getMinVer(runtime.Version()); e == nil && v <= ginSupportMinGoVer {
|
||||||
debugPrint(`[WARNING] Now Gin requires Go 1.8 or later and Go 1.9 will be required soon.
|
debugPrint(`[WARNING] Now Gin requires Go 1.6 or later and Go 1.7 will be required soon.
|
||||||
|
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
@ -97,8 +97,6 @@ at initialization. ie. before any route is registered or the router is listening
|
|||||||
|
|
||||||
func debugPrintError(err error) {
|
func debugPrintError(err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if IsDebugging() {
|
debugPrint("[ERROR] %v\n", err)
|
||||||
fmt.Fprintf(DefaultErrorWriter, "[GIN-debug] [ERROR] %v\n", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,10 @@
|
|||||||
package gin
|
package gin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin/internal/json"
|
"github.com/gin-gonic/gin/internal/json"
|
||||||
|
"reflect"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ErrorType is an unsigned 64-bit error code as defined in the gin spec.
|
// ErrorType is an unsigned 64-bit error code as defined in the gin spec.
|
||||||
@ -158,7 +157,7 @@ func (a errorMsgs) String() string {
|
|||||||
if len(a) == 0 {
|
if len(a) == 0 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
var buffer bytes.Buffer
|
var buffer strings.Builder
|
||||||
for i, msg := range a {
|
for i, msg := range a {
|
||||||
fmt.Fprintf(&buffer, "Error #%02d: %s\n", i+1, msg.Err)
|
fmt.Fprintf(&buffer, "Error #%02d: %s\n", i+1, msg.Err)
|
||||||
if msg.Meta != nil {
|
if msg.Meta != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user