-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenv.go
56 lines (47 loc) · 953 Bytes
/
env.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package scene
import "os"
type Environment uint8
const (
EnvDevelopment Environment = iota
EnvProduction
EnvTest
)
func (e Environment) String() string {
switch e {
case EnvDevelopment:
return "development"
case EnvProduction:
return "production"
case EnvTest:
return "test"
default:
return "unknown"
}
}
var env Environment = EnvDevelopment
// DEFAULT_ENV is the environment variable that can be set to "production", "test" or "development"
// this is the default
var DEFAULT_ENV string = "development"
func init() {
// override the default environment setting
envStr := DEFAULT_ENV
if os.Getenv("SCENE_ENV") != "" {
envStr = os.Getenv("SCENE_ENV")
}
switch envStr {
case "production":
env = EnvProduction
case "development":
env = EnvDevelopment
case "test":
env = EnvTest
default:
env = EnvDevelopment
}
}
func SetEnvironment(e Environment) {
env = e
}
func GetEnvironment() Environment {
return env
}