2014-08-29 17:49:50 +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.
|
|
|
|
|
2014-08-19 01:40:52 +00:00
|
|
|
package gin
|
|
|
|
|
|
|
|
import (
|
2015-03-23 03:40:33 +00:00
|
|
|
"log"
|
2014-08-19 01:40:52 +00:00
|
|
|
"os"
|
2015-04-07 16:37:17 +00:00
|
|
|
|
|
|
|
"github.com/mattn/go-colorable"
|
2014-08-19 01:40:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const GIN_MODE = "GIN_MODE"
|
|
|
|
|
|
|
|
const (
|
|
|
|
DebugMode string = "debug"
|
|
|
|
ReleaseMode string = "release"
|
2014-08-20 23:01:05 +00:00
|
|
|
TestMode string = "test"
|
2014-08-19 01:40:52 +00:00
|
|
|
)
|
|
|
|
const (
|
|
|
|
debugCode = iota
|
|
|
|
releaseCode = iota
|
2014-08-20 23:01:05 +00:00
|
|
|
testCode = iota
|
2014-08-19 01:40:52 +00:00
|
|
|
)
|
|
|
|
|
2015-04-07 16:37:17 +00:00
|
|
|
var DefaultLogFile = colorable.NewColorableStdout()
|
2015-04-07 10:27:23 +00:00
|
|
|
var ginMode int = debugCode
|
|
|
|
var modeName string = DebugMode
|
2014-08-19 01:40:52 +00:00
|
|
|
|
2014-10-08 23:40:42 +00:00
|
|
|
func init() {
|
|
|
|
value := os.Getenv(GIN_MODE)
|
|
|
|
if len(value) == 0 {
|
|
|
|
SetMode(DebugMode)
|
|
|
|
} else {
|
|
|
|
SetMode(value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-19 01:40:52 +00:00
|
|
|
func SetMode(value string) {
|
|
|
|
switch value {
|
|
|
|
case DebugMode:
|
2015-04-07 10:27:23 +00:00
|
|
|
ginMode = debugCode
|
2014-08-19 01:40:52 +00:00
|
|
|
case ReleaseMode:
|
2015-04-07 10:27:23 +00:00
|
|
|
ginMode = releaseCode
|
2014-08-20 23:01:05 +00:00
|
|
|
case TestMode:
|
2015-04-07 10:27:23 +00:00
|
|
|
ginMode = testCode
|
2014-08-19 01:40:52 +00:00
|
|
|
default:
|
2015-03-23 04:50:10 +00:00
|
|
|
log.Panic("gin mode unknown: " + value)
|
2014-08-19 01:40:52 +00:00
|
|
|
}
|
2015-04-07 10:27:23 +00:00
|
|
|
modeName = value
|
2014-09-08 18:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Mode() string {
|
2015-04-07 10:27:23 +00:00
|
|
|
return modeName
|
2014-08-19 01:40:52 +00:00
|
|
|
}
|