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 (
|
2014-10-09 03:40:42 +04:00
|
|
|
"fmt"
|
2014-08-19 05:40:52 +04:00
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
const GIN_MODE = "GIN_MODE"
|
|
|
|
|
|
|
|
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
|
|
|
)
|
|
|
|
|
|
|
|
var gin_mode int = debugCode
|
2014-09-08 22:54:08 +04:00
|
|
|
var mode_name string = DebugMode
|
2014-08-19 05:40:52 +04:00
|
|
|
|
2014-10-09 03:40:42 +04:00
|
|
|
func init() {
|
|
|
|
value := os.Getenv(GIN_MODE)
|
|
|
|
if len(value) == 0 {
|
|
|
|
SetMode(DebugMode)
|
|
|
|
} else {
|
|
|
|
SetMode(value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-19 05:40:52 +04:00
|
|
|
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
|
2014-08-19 05:40:52 +04:00
|
|
|
default:
|
2014-10-09 03:40:42 +04:00
|
|
|
panic("gin mode unknown: " + value)
|
2014-08-19 05:40:52 +04:00
|
|
|
}
|
2014-09-08 22:54:08 +04:00
|
|
|
mode_name = value
|
|
|
|
}
|
|
|
|
|
|
|
|
func Mode() string {
|
|
|
|
return mode_name
|
2014-08-19 05:40:52 +04:00
|
|
|
}
|
|
|
|
|
2014-10-08 23:37:26 +04:00
|
|
|
func IsDebugging() bool {
|
|
|
|
return gin_mode == debugCode
|
|
|
|
}
|
|
|
|
|
2014-10-09 03:40:42 +04:00
|
|
|
func debugPrint(format string, values ...interface{}) {
|
|
|
|
if IsDebugging() {
|
|
|
|
fmt.Printf("[GIN-debug] "+format, values)
|
2014-08-19 05:40:52 +04:00
|
|
|
}
|
|
|
|
}
|