2014-08-29 21:49:50 +04: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.
|
|
|
|
|
2014-08-19 05:40:52 +04:00
|
|
|
package gin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2015-04-07 19:37:17 +03:00
|
|
|
|
2015-05-31 18:03:15 +03:00
|
|
|
"github.com/gin-gonic/gin/binding"
|
2014-08-19 05:40:52 +04:00
|
|
|
)
|
|
|
|
|
2015-05-22 17:55:16 +03:00
|
|
|
const ENV_GIN_MODE = "GIN_MODE"
|
2014-08-19 05:40:52 +04:00
|
|
|
|
|
|
|
const (
|
|
|
|
DebugMode string = "debug"
|
|
|
|
ReleaseMode string = "release"
|
2014-08-21 03:01:05 +04:00
|
|
|
TestMode string = "test"
|
2014-08-19 05:40:52 +04:00
|
|
|
)
|
|
|
|
const (
|
|
|
|
debugCode = iota
|
|
|
|
releaseCode = iota
|
2014-08-21 03:01:05 +04:00
|
|
|
testCode = iota
|
2014-08-19 05:40:52 +04:00
|
|
|
)
|
|
|
|
|
2016-01-26 20:53:00 +03:00
|
|
|
// 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:
|
2016-01-27 00:40:29 +03:00
|
|
|
// import "github.com/mattn/go-colorable"
|
|
|
|
// gin.DefaultWriter = colorable.NewColorableStdout()
|
2016-04-15 02:16:46 +03:00
|
|
|
var DefaultWriter = os.Stdout
|
|
|
|
var DefaultErrorWriter = os.Stderr
|
2016-01-26 20:53:00 +03:00
|
|
|
|
2016-04-15 02:16:46 +03:00
|
|
|
var ginMode = debugCode
|
|
|
|
var modeName = DebugMode
|
2014-08-19 05:40:52 +04:00
|
|
|
|
2014-10-09 03:40:42 +04:00
|
|
|
func init() {
|
2015-05-22 17:55:16 +03:00
|
|
|
mode := os.Getenv(ENV_GIN_MODE)
|
|
|
|
if len(mode) == 0 {
|
2014-10-09 03:40:42 +04:00
|
|
|
SetMode(DebugMode)
|
|
|
|
} else {
|
2015-05-22 17:55:16 +03:00
|
|
|
SetMode(mode)
|
2014-10-09 03:40:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-19 05:40:52 +04:00
|
|
|
func SetMode(value string) {
|
|
|
|
switch value {
|
|
|
|
case DebugMode:
|
2015-04-07 13:27:23 +03:00
|
|
|
ginMode = debugCode
|
2014-08-19 05:40:52 +04:00
|
|
|
case ReleaseMode:
|
2015-04-07 13:27:23 +03:00
|
|
|
ginMode = releaseCode
|
2014-08-21 03:01:05 +04:00
|
|
|
case TestMode:
|
2015-04-07 13:27:23 +03:00
|
|
|
ginMode = testCode
|
2014-08-19 05:40:52 +04:00
|
|
|
default:
|
2015-04-08 03:58:35 +03:00
|
|
|
panic("gin mode unknown: " + value)
|
2014-08-19 05:40:52 +04:00
|
|
|
}
|
2015-04-07 13:27:23 +03:00
|
|
|
modeName = value
|
2014-09-08 22:54:08 +04:00
|
|
|
}
|
|
|
|
|
2015-05-31 18:03:15 +03:00
|
|
|
func DisableBindValidation() {
|
|
|
|
binding.Validator = nil
|
|
|
|
}
|
|
|
|
|
2014-09-08 22:54:08 +04:00
|
|
|
func Mode() string {
|
2015-04-07 13:27:23 +03:00
|
|
|
return modeName
|
2014-08-19 05:40:52 +04:00
|
|
|
}
|