/
detectenv.go
72 lines (60 loc) · 1.73 KB
/
detectenv.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
72
package main
import (
"os"
"path/filepath"
"strings"
"github.com/xiaonanln/goworld/engine/config"
)
// Env represents environment variables
type Env struct {
GoWorldRoot string
}
// GetDispatcherDir returns the path to the dispatcher
func (env *Env) GetDispatcherDir() string {
return filepath.Join(env.GoWorldRoot, "components", "dispatcher")
}
// GetGateDir returns the path to the gate
func (env *Env) GetGateDir() string {
return filepath.Join(env.GoWorldRoot, "components", "gate")
}
// GetDispatcherBinary returns the path to the dispatcher binary
func (env *Env) GetDispatcherBinary() string {
return filepath.Join(env.GetDispatcherDir(), "dispatcher"+BinaryExtension)
}
// GetGateBinary returns the path to the gate binary
func (env *Env) GetGateBinary() string {
return filepath.Join(env.GetGateDir(), "gate"+BinaryExtension)
}
var env Env
func getGoSearchPaths() []string {
var paths []string
goroot := os.Getenv("GOROOT")
if goroot != "" {
paths = append(paths, goroot)
}
gopath := os.Getenv("GOPATH")
for _, p := range strings.Split(gopath, string(os.PathListSeparator)) {
if p != "" {
paths = append(paths, p)
}
}
return paths
}
func detectGoWorldPath() {
searchPaths := getGoSearchPaths()
showMsg("go search paths: %s", strings.Join(searchPaths, string(os.PathListSeparator)))
for _, sp := range searchPaths {
goworldPath := filepath.Join(sp, "src", "github.com", "xiaonanln", "goworld")
if isdir(goworldPath) {
env.GoWorldRoot = goworldPath
break
}
}
if env.GoWorldRoot == "" {
showMsgAndQuit("goworld directory is not detected")
}
showMsg("goworld directory found: %s", env.GoWorldRoot)
configFile := filepath.Join(env.GoWorldRoot, "goworld.ini")
config.SetConfigFile(configFile)
//config.Get()
}