-
Notifications
You must be signed in to change notification settings - Fork 2
/
env.go
60 lines (48 loc) · 1.14 KB
/
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
57
58
59
60
package env
import (
"fmt"
"os"
"strings"
)
var activated *environment
type environment struct {
value string
}
func (e *environment) Value() string {
return e.value
}
func (e *environment) IsDev() bool {
return e.value == "dev"
}
func (e *environment) IsTest() bool {
return e.value == "test"
}
func (e *environment) IsPre() bool {
return e.value == "pre"
}
func (e *environment) IsProd() bool {
return e.value == "prod"
}
func (e *environment) t() {}
func init() {
switch strings.ToLower(strings.TrimSpace(os.Getenv("env"))) {
case "dev":
activated = &environment{value: "dev"}
case "test":
activated = &environment{value: "test"}
case "pre":
activated = &environment{value: "pre"}
case "prod":
activated = &environment{value: "prod"}
default:
activated = &environment{value: "test"}
fmt.Println("Warning: environment 'env' don't found or it's illegal, the default 'test' will be used.")
}
fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
fmt.Println("'env' is " + activated.Value())
fmt.Println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
}
// Activated the activated env
func Activated() *environment {
return activated
}