diff --git a/auth.go b/auth.go index 9e5d4cf6..43ad36f5 100644 --- a/auth.go +++ b/auth.go @@ -70,8 +70,9 @@ func BasicAuth(accounts Accounts) HandlerFunc { } func processAccounts(accounts Accounts) authPairs { - assert1(len(accounts) > 0, "Empty list of authorized credentials") - pairs := make(authPairs, 0, len(accounts)) + length := len(accounts) + assert1(length > 0, "Empty list of authorized credentials") + pairs := make(authPairs, 0, length) for user, password := range accounts { assert1(user != "", "User can not be empty") value := authorizationHeader(user, password) diff --git a/context.go b/context.go index fb7f54e9..01cff1ae 100644 --- a/context.go +++ b/context.go @@ -34,9 +34,11 @@ const ( MIMEPOSTForm = binding.MIMEPOSTForm MIMEMultipartPOSTForm = binding.MIMEMultipartPOSTForm MIMEYAML = binding.MIMEYAML - BodyBytesKey = "_gin-gonic/gin/bodybyteskey" ) +// BodyBytesKey indicates a default body bytes key. +const BodyBytesKey = "_gin-gonic/gin/bodybyteskey" + const abortIndex int8 = math.MaxInt8 / 2 // Context is the most important part of gin. It allows us to pass variables between middleware, diff --git a/gin.go b/gin.go index ab1d0a46..888be36b 100644 --- a/gin.go +++ b/gin.go @@ -20,11 +20,12 @@ import ( const defaultMultipartMemory = 32 << 20 // 32 MB var ( - default404Body = []byte("404 page not found") - default405Body = []byte("405 method not allowed") - defaultAppEngine bool + default404Body = []byte("404 page not found") + default405Body = []byte("405 method not allowed") ) +var defaultAppEngine bool + // HandlerFunc defines the handler used by gin middleware as return value. type HandlerFunc func(*Context) diff --git a/mode.go b/mode.go index ca3677a9..11f833e9 100644 --- a/mode.go +++ b/mode.go @@ -22,6 +22,7 @@ const ( // TestMode indicates gin mode is test. TestMode = "test" ) + const ( debugCode = iota releaseCode diff --git a/path.go b/path.go index 51346e4a..d42d6b9d 100644 --- a/path.go +++ b/path.go @@ -136,10 +136,11 @@ func bufApp(buf *[]byte, s string, w int, c byte) { // Otherwise use either the stack buffer, if it is large enough, or // allocate a new buffer on the heap, and copy all previous characters. - if l := len(s); l > cap(b) { - *buf = make([]byte, len(s)) + length := len(s) + if length > cap(b) { + *buf = make([]byte, length) } else { - *buf = (*buf)[:l] + *buf = (*buf)[:length] } b = *buf diff --git a/recovery.go b/recovery.go index bc946c03..8cf0932a 100644 --- a/recovery.go +++ b/recovery.go @@ -146,6 +146,6 @@ func function(pc uintptr) []byte { } func timeFormat(t time.Time) string { - var timeString = t.Format("2006/01/02 - 15:04:05") + timeString := t.Format("2006/01/02 - 15:04:05") return timeString }