gin/mode.go

56 lines
942 B
Go
Raw Permalink Normal View History

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.
package gin
import (
"os"
2015-04-07 19:37:17 +03:00
"github.com/mattn/go-colorable"
)
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 DefaultWriter = colorable.NewColorableStdout()
2015-04-07 13:27:23 +03:00
var ginMode int = debugCode
var modeName string = DebugMode
2014-10-09 03:40:42 +04:00
func init() {
value := os.Getenv(GIN_MODE)
if len(value) == 0 {
SetMode(DebugMode)
} else {
SetMode(value)
}
}
func SetMode(value string) {
switch value {
case DebugMode:
2015-04-07 13:27:23 +03:00
ginMode = debugCode
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
default:
2015-04-08 03:58:35 +03:00
panic("gin mode unknown: " + value)
}
2015-04-07 13:27:23 +03:00
modeName = value
}
func Mode() string {
2015-04-07 13:27:23 +03:00
return modeName
}