1 Star 0 Fork 0

wuzpdev / goworld

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
detectenv.go 1.73 KB
一键复制 编辑 原始数据 按行查看 历史
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()
}
1
https://gitee.com/wuzpdev/goworld.git
git@gitee.com:wuzpdev/goworld.git
wuzpdev
goworld
goworld
v0.1.6

搜索帮助