Skip to content

Commit

Permalink
gin mode unknown: show available mode (gin-gonic#2567) (#21)
Browse files Browse the repository at this point in the history
Co-authored-by: thinkerou <[email protected]>
Co-authored-by: J. J. Bigorra <[email protected]>
Co-authored-by: Rubi <[email protected]>
Co-authored-by: Qt <[email protected]>
Co-authored-by: Josep Jesus Bigorra Algaba <[email protected]>
Co-authored-by: Snawoot <[email protected]>
  • Loading branch information
7 people authored Jan 15, 2021
1 parent ae84288 commit a0687a5
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1793,8 +1793,8 @@ func main() {
// Initializing the server in a goroutine so that
// it won't block the graceful shutdown handling below
go func() {
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Fatalf("listen: %s\n", err)
if err := srv.ListenAndServe(); err != nil && errors.Is(err, http.ErrServerClosed) {
log.Printf("listen: %s\n", err)
}
}()

Expand All @@ -1812,6 +1812,7 @@ func main() {
// the request it is currently handling
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

if err := srv.Shutdown(ctx); err != nil {
log.Fatal("Server forced to shutdown:", err)
}
Expand Down
3 changes: 2 additions & 1 deletion auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package gin

import (
"crypto/subtle"
"encoding/base64"
"net/http"
"strconv"
Expand All @@ -30,7 +31,7 @@ func (a authPairs) searchCredential(authValue string) (string, bool) {
return "", false
}
for _, pair := range a {
if pair.value == authValue {
if subtle.ConstantTimeCompare([]byte(pair.value), []byte(authValue)) == 1 {
return pair.user, true
}
}
Expand Down
4 changes: 2 additions & 2 deletions debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"strings"
)

const ginSupportMinGoVer = 10
const ginSupportMinGoVer = 12

// IsDebugging returns true if the framework is running in debug mode.
// Use SetMode(gin.ReleaseMode) to disable debug mode.
Expand Down Expand Up @@ -67,7 +67,7 @@ func getMinVer(v string) (uint64, error) {

func debugPrintWARNINGDefault() {
if v, e := getMinVer(runtime.Version()); e == nil && v <= ginSupportMinGoVer {
debugPrint(`[WARNING] Now Gin requires Go 1.11 or later and Go 1.12 will be required soon.
debugPrint(`[WARNING] Now Gin requires Go 1.12+.
`)
}
Expand Down
2 changes: 1 addition & 1 deletion debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func TestDebugPrintWARNINGDefault(t *testing.T) {
})
m, e := getMinVer(runtime.Version())
if e == nil && m <= ginSupportMinGoVer {
assert.Equal(t, "[GIN-debug] [WARNING] Now Gin requires Go 1.11 or later and Go 1.12 will be required soon.\n\n[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.\n\n", re)
assert.Equal(t, "[GIN-debug] [WARNING] Now Gin requires Go 1.12+.\n\n[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.\n\n", re)
} else {
assert.Equal(t, "[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.\n\n", re)
}
Expand Down
2 changes: 1 addition & 1 deletion mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func SetMode(value string) {
case TestMode:
ginMode = testCode
default:
panic("gin mode unknown: " + value)
panic("gin mode unknown: " + value + " (available mode: debug release test)")
}

modeName = value
Expand Down

0 comments on commit a0687a5

Please sign in to comment.