diff --git a/conf/wide.go b/conf/wide.go index 908a6c6..17b4440 100644 --- a/conf/wide.go +++ b/conf/wide.go @@ -22,7 +22,8 @@ type conf struct { ContextPath string StaticPath string RuntimeMode string - GOPATH string + Repos string + UserRepos string } var Wide conf @@ -47,16 +48,18 @@ func init() { glog.Infof("IP [%s]", ip) Wide.Server = strings.Replace(Wide.Server, "{IP}", ip, 1) Wide.StaticServer = strings.Replace(Wide.StaticServer, "{IP}", ip, 1) - Wide.EditorChannel = strings.Replace(Wide.EditorChannel, "{IP}", ip, 1) Wide.OutputChannel = strings.Replace(Wide.OutputChannel, "{IP}", ip, 1) Wide.ShellChannel = strings.Replace(Wide.ShellChannel, "{IP}", ip, 1) + // 获取当前执行路径 file, _ := exec.LookPath(os.Args[0]) pwd, _ := filepath.Abs(file) pwd = pwd[:strings.LastIndex(pwd, string(os.PathSeparator))] glog.Infof("pwd [%s]", pwd) - Wide.GOPATH = strings.Replace(Wide.GOPATH, "{pwd}", pwd, 1) + + Wide.Repos = strings.Replace(Wide.Repos, "{pwd}", pwd, 1) + Wide.UserRepos = strings.Replace(Wide.UserRepos, "{pwd}", pwd, 1) glog.Info("Conf: \n" + string(bytes)) } diff --git a/conf/wide.json b/conf/wide.json index 185c257..0fb58e3 100644 --- a/conf/wide.json +++ b/conf/wide.json @@ -8,5 +8,6 @@ "ContextPath": "", "StaticPath": "", "RuntimeMode": "dev", - "GOPATH": "{pwd}/data" + "Repos": "{pwd}/data/repos/src", + "UserRepos": "{pwd}/data/user_repos/{user}/src" } diff --git a/data/src/hello/main.go b/data/repos/src/hello/main.go similarity index 100% rename from data/src/hello/main.go rename to data/repos/src/hello/main.go diff --git a/data/src/performance/main.go b/data/repos/src/performance/main.go similarity index 100% rename from data/src/performance/main.go rename to data/repos/src/performance/main.go diff --git a/data/src/time/time.go b/data/repos/src/time/time.go similarity index 100% rename from data/src/time/time.go rename to data/repos/src/time/time.go diff --git a/file/files.go b/file/files.go index a2e2803..f38a3ce 100644 --- a/file/files.go +++ b/file/files.go @@ -15,10 +15,10 @@ import ( func GetFiles(w http.ResponseWriter, r *http.Request) { data := map[string]interface{}{"succ": true} - root := FileNode{"projects", conf.Wide.GOPATH, "d", []*FileNode{}} - fileInfo, _ := os.Lstat(conf.Wide.GOPATH) + root := FileNode{"projects", conf.Wide.Repos, "d", []*FileNode{}} + fileInfo, _ := os.Lstat(conf.Wide.Repos) - walk(conf.Wide.GOPATH, fileInfo, &root) + walk(conf.Wide.Repos, fileInfo, &root) data["root"] = root diff --git a/output/outputs.go b/output/outputs.go index 6be1e2a..1f37fa9 100644 --- a/output/outputs.go +++ b/output/outputs.go @@ -214,5 +214,6 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { } func setCmdEnv(cmd *exec.Cmd) { - cmd.Env = append(cmd.Env, "GOPATH="+conf.Wide.GOPATH, "GOROOT="+os.Getenv("GOROOT")) + // TODO: 使用用户自己的仓库路径设置 GOPATH + cmd.Env = append(cmd.Env, "GOPATH="+conf.Wide.Repos, "GOROOT="+os.Getenv("GOROOT")) } diff --git a/shell/shells.go b/shell/shells.go index a261603..649a3ad 100644 --- a/shell/shells.go +++ b/shell/shells.go @@ -96,8 +96,9 @@ func pipeCommands(commands ...*exec.Cmd) string { } func setCmdEnv(cmd *exec.Cmd) { - cmd.Env = append(cmd.Env, "TERM=xterm", "GOPATH="+conf.Wide.GOPATH, + // TODO: 使用用户自己的仓库路径设置 GOPATH + cmd.Env = append(cmd.Env, "TERM=xterm", "GOPATH="+conf.Wide.Repos, "GOROOT="+os.Getenv("GOROOT")) - cmd.Dir = conf.Wide.GOPATH + cmd.Dir = conf.Wide.Repos }