支持多用户的源码仓库模型

This commit is contained in:
Liang Ding 2014-08-28 10:51:03 +08:00
parent befb16c2b8
commit 3d36e37153
8 changed files with 16 additions and 10 deletions

View File

@ -22,7 +22,8 @@ type conf struct {
ContextPath string ContextPath string
StaticPath string StaticPath string
RuntimeMode string RuntimeMode string
GOPATH string Repos string
UserRepos string
} }
var Wide conf var Wide conf
@ -47,16 +48,18 @@ func init() {
glog.Infof("IP [%s]", ip) glog.Infof("IP [%s]", ip)
Wide.Server = strings.Replace(Wide.Server, "{IP}", ip, 1) Wide.Server = strings.Replace(Wide.Server, "{IP}", ip, 1)
Wide.StaticServer = strings.Replace(Wide.StaticServer, "{IP}", ip, 1) Wide.StaticServer = strings.Replace(Wide.StaticServer, "{IP}", ip, 1)
Wide.EditorChannel = strings.Replace(Wide.EditorChannel, "{IP}", ip, 1) Wide.EditorChannel = strings.Replace(Wide.EditorChannel, "{IP}", ip, 1)
Wide.OutputChannel = strings.Replace(Wide.OutputChannel, "{IP}", ip, 1) Wide.OutputChannel = strings.Replace(Wide.OutputChannel, "{IP}", ip, 1)
Wide.ShellChannel = strings.Replace(Wide.ShellChannel, "{IP}", ip, 1) Wide.ShellChannel = strings.Replace(Wide.ShellChannel, "{IP}", ip, 1)
// 获取当前执行路径
file, _ := exec.LookPath(os.Args[0]) file, _ := exec.LookPath(os.Args[0])
pwd, _ := filepath.Abs(file) pwd, _ := filepath.Abs(file)
pwd = pwd[:strings.LastIndex(pwd, string(os.PathSeparator))] pwd = pwd[:strings.LastIndex(pwd, string(os.PathSeparator))]
glog.Infof("pwd [%s]", pwd) 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)) glog.Info("Conf: \n" + string(bytes))
} }

View File

@ -8,5 +8,6 @@
"ContextPath": "", "ContextPath": "",
"StaticPath": "", "StaticPath": "",
"RuntimeMode": "dev", "RuntimeMode": "dev",
"GOPATH": "{pwd}/data" "Repos": "{pwd}/data/repos/src",
"UserRepos": "{pwd}/data/user_repos/{user}/src"
} }

View File

@ -15,10 +15,10 @@ import (
func GetFiles(w http.ResponseWriter, r *http.Request) { func GetFiles(w http.ResponseWriter, r *http.Request) {
data := map[string]interface{}{"succ": true} data := map[string]interface{}{"succ": true}
root := FileNode{"projects", conf.Wide.GOPATH, "d", []*FileNode{}} root := FileNode{"projects", conf.Wide.Repos, "d", []*FileNode{}}
fileInfo, _ := os.Lstat(conf.Wide.GOPATH) fileInfo, _ := os.Lstat(conf.Wide.Repos)
walk(conf.Wide.GOPATH, fileInfo, &root) walk(conf.Wide.Repos, fileInfo, &root)
data["root"] = root data["root"] = root

View File

@ -214,5 +214,6 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
} }
func setCmdEnv(cmd *exec.Cmd) { 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"))
} }

View File

@ -96,8 +96,9 @@ func pipeCommands(commands ...*exec.Cmd) string {
} }
func setCmdEnv(cmd *exec.Cmd) { 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")) "GOROOT="+os.Getenv("GOROOT"))
cmd.Dir = conf.Wide.GOPATH cmd.Dir = conf.Wide.Repos
} }