diff --git a/mode.go b/mode.go index 9c4f0246..9df4e45f 100644 --- a/mode.go +++ b/mode.go @@ -53,6 +53,9 @@ func SetMode(value string) { default: panic("gin mode unknown: " + value) } + if value == "" { + value = DebugMode + } modeName = value } diff --git a/mode_test.go b/mode_test.go index 7eaca823..cf27acd8 100644 --- a/mode_test.go +++ b/mode_test.go @@ -21,6 +21,10 @@ func TestSetMode(t *testing.T) { assert.Equal(t, TestMode, Mode()) os.Unsetenv(ENV_GIN_MODE) + SetMode("") + assert.Equal(t, debugCode, ginMode) + assert.Equal(t, DebugMode, Mode()) + SetMode(DebugMode) assert.Equal(t, debugCode, ginMode) assert.Equal(t, DebugMode, Mode())