gin/mode.go

43 lines
653 B
Go
Raw Normal View History

package gin
import (
"os"
)
const GIN_MODE = "GIN_MODE"
const (
DebugMode string = "debug"
ReleaseMode string = "release"
2014-08-21 03:01:05 +04:00
TestMode string = "test"
)
const (
debugCode = iota
releaseCode = iota
2014-08-21 03:01:05 +04:00
testCode = iota
)
var gin_mode int = debugCode
func SetMode(value string) {
switch value {
case DebugMode:
gin_mode = debugCode
case ReleaseMode:
gin_mode = releaseCode
2014-08-21 03:01:05 +04:00
case TestMode:
gin_mode = testCode
default:
panic("gin mode unknown, the allowed modes are: " + DebugMode + " and " + ReleaseMode)
}
}
func init() {
value := os.Getenv(GIN_MODE)
if len(value) == 0 {
SetMode(DebugMode)
} else {
SetMode(value)
}
}