-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathenv.go
66 lines (53 loc) · 1.05 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
61
62
63
64
65
66
package env
import (
"os"
)
// Env type.
type Env string
// Popular environments.
const (
Development Env = "development"
Testing Env = "testing"
Staging Env = "staging"
Production Env = "production"
)
const (
decimalBase = 10
bitSize8 = 8
bitSize16 = 16
bitSize32 = 32
bitSize64 = 64
)
// Environment returns ENV value in environment variables.
func Environment() Env {
return Env(os.Getenv("ENV"))
}
// Is checks whether ENV is what you expected or not.
func Is(e1 Env, ee ...Env) bool {
ce := Environment()
if e1 == ce {
return true
}
for i := range ee {
if ee[i] == ce {
return true
}
}
return false
}
// IsDevelopment checks whether ENV is development or not.
func IsDevelopment() bool {
return Is(Development)
}
// IsTesting checks whether ENV is testing or not.
func IsTesting() bool {
return Is(Testing)
}
// IsStaging checks whether ENV is staging or not.
func IsStaging() bool {
return Is(Staging)
}
// IsProduction checks whether ENV is production or not.
func IsProduction() bool {
return Is(Production)
}