-
Notifications
You must be signed in to change notification settings - Fork 1
/
env.go
71 lines (57 loc) · 1.08 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
67
68
69
70
71
package echotool
import (
"os"
"path/filepath"
"strings"
"github.com/popeyeio/handy"
)
const (
runtimeEnv = "_ENV_"
runtimeRegion = "_REGION_"
runtimeTag = "_TAG_"
EnvDev = "dev"
EnvTest = "test"
EnvProduct = "prod"
confPath = "/conf"
regionDefault = "cn"
)
func IsProduct() bool {
return Env() == EnvProduct
}
func IsTest() bool {
return Env() == EnvTest
}
func GetConfDir() string {
dir, _ := os.Getwd()
return dir + confPath
}
func Env() (env string) {
switch os.Getenv(runtimeEnv) {
case EnvTest:
env = EnvTest
case EnvProduct:
env = EnvProduct
default:
env = EnvDev
}
return
}
func Reg() string {
reg := regionDefault
if r := os.Getenv(runtimeRegion); !handy.IsEmptyStr(r) {
reg = strings.ToLower(r)
}
return reg
}
func Tag() string {
return strings.ToLower(os.Getenv(runtimeTag))
}
func ParseByEnv(suffix string) string {
return filepath.Join(Env(), suffix)
}
func ParseByReg(suffix string) string {
return filepath.Join(Env(), Reg(), suffix)
}
func ParseByTag(suffix string) string {
return filepath.Join(Env(), Tag(), suffix)
}