-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrootdir.go
More file actions
58 lines (48 loc) · 813 Bytes
/
rootdir.go
File metadata and controls
58 lines (48 loc) · 813 Bytes
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
package conf
import (
"os"
"path/filepath"
)
func envRoot() string {
dir := os.Getenv("PRJ_ROOT")
if len(dir) == 0 {
// Compatible the old version
dir = os.Getenv("PJ_ROOT")
}
if len(dir) == 0 {
panic("Need PRJ_ROOT environment for project directory")
}
p, err := filepath.Abs(dir)
if err != nil {
panic(err)
}
return p
}
func envEtc() string {
dir := os.Getenv("ETC_ROOT")
if len(dir) == 0 {
return envRoot()
}
p, err := filepath.Abs(dir)
if err != nil {
panic(err)
}
return p
}
var (
rootDir = ""
)
func InitRootDir(path string) {
rootDir = path
}
// project root path
func RootDir() string {
if len(rootDir) == 0 {
rootDir = envRoot()
}
return rootDir
}
// project root for etc, if not set, return then project root path
func EtcDir() string {
return envEtc()
}