mtfosbot/vendor/github.com/gin-gonic/gin/mode.go

73 lines
1.4 KiB
Go
Raw Permalink Normal View History

2018-08-14 09:25:34 +00:00
// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package gin
import (
"io"
"os"
"github.com/gin-gonic/gin/binding"
)
const ENV_GIN_MODE = "GIN_MODE"
const (
2018-11-16 03:10:19 +00:00
DebugMode = "debug"
ReleaseMode = "release"
TestMode = "test"
2018-08-14 09:25:34 +00:00
)
const (
debugCode = iota
releaseCode
testCode
)
// DefaultWriter is the default io.Writer used the Gin for debug output and
// middleware output like Logger() or Recovery().
// Note that both Logger and Recovery provides custom ways to configure their
// output io.Writer.
// To support coloring in Windows use:
// import "github.com/mattn/go-colorable"
// gin.DefaultWriter = colorable.NewColorableStdout()
var DefaultWriter io.Writer = os.Stdout
var DefaultErrorWriter io.Writer = os.Stderr
var ginMode = debugCode
var modeName = DebugMode
func init() {
mode := os.Getenv(ENV_GIN_MODE)
2018-11-16 03:10:19 +00:00
SetMode(mode)
2018-08-14 09:25:34 +00:00
}
func SetMode(value string) {
switch value {
2018-11-16 03:10:19 +00:00
case DebugMode, "":
2018-08-14 09:25:34 +00:00
ginMode = debugCode
case ReleaseMode:
ginMode = releaseCode
case TestMode:
ginMode = testCode
default:
panic("gin mode unknown: " + value)
}
2018-11-16 03:10:19 +00:00
if value == "" {
value = DebugMode
}
2018-08-14 09:25:34 +00:00
modeName = value
}
func DisableBindValidation() {
binding.Validator = nil
}
2018-11-16 03:10:19 +00:00
func EnableJsonDecoderUseNumber() {
binding.EnableDecoderUseNumber = true
}
2018-08-14 09:25:34 +00:00
func Mode() string {
return modeName
}