From 3d36e37153d84e9fa9e52e5d18e34d1945392774 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 28 Aug 2014 10:51:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=A4=9A=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=9A=84=E6=BA=90=E7=A0=81=E4=BB=93=E5=BA=93=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf/wide.go | 9 ++++++--- conf/wide.json | 3 ++- data/{ => repos}/src/hello/main.go | 0 data/{ => repos}/src/performance/main.go | 0 data/{ => repos}/src/time/time.go | 0 file/files.go | 6 +++--- output/outputs.go | 3 ++- shell/shells.go | 5 +++-- 8 files changed, 16 insertions(+), 10 deletions(-) rename data/{ => repos}/src/hello/main.go (100%) rename data/{ => repos}/src/performance/main.go (100%) rename data/{ => repos}/src/time/time.go (100%) 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 }