From 4f48e827f67b19bb567c405e692129a0e626981c Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 17 May 2019 01:06:01 +0800 Subject: [PATCH] :art: #347 --- conf/user.go | 2 +- conf/wide.go | 10 +--------- main.go | 4 ++-- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/conf/user.go b/conf/user.go index 947b516..1fed387 100644 --- a/conf/user.go +++ b/conf/user.go @@ -122,7 +122,7 @@ func NewUser(id, name, avatar, workspace string) *User { // 2. Replace ${GOPATH} with enviorment variable GOPATH // 3. Replace "/" with "\\" (Windows) func (u *User) WorkspacePath() string { - w := strings.Replace(u.Workspace, "{WD}", Wide.WD, 1) + w := u.Workspace w = strings.Replace(w, "${GOPATH}", os.Getenv("GOPATH"), 1) return filepath.FromSlash(w) diff --git a/conf/wide.go b/conf/wide.go index 1c1adec..2d993e7 100644 --- a/conf/wide.go +++ b/conf/wide.go @@ -63,7 +63,6 @@ type conf struct { StaticResourceVersion string // version of static resources MaxProcs int // Go max procs RuntimeMode string // runtime mode (dev/prod) - WD string // current working direcitory, ${pwd} Locale string // default locale Playground string // playground directory Users string // users directory @@ -189,10 +188,6 @@ func initWide(confPath, confUsers, confServer, confLogLevel, confPlayground stri logger.Debug("Conf: \n" + string(bytes)) - // Working Directory - Wide.WD = util.OS.Pwd() - logger.Debugf("${pwd} [%s]", Wide.WD) - // User Home home, err := util.OS.Home() if nil != err { @@ -224,7 +219,6 @@ func initWide(confPath, confUsers, confServer, confLogLevel, confPlayground stri } // Users' workspaces directory - Wide.UsersWorkspaces = strings.Replace(Wide.UsersWorkspaces, "${WD}", Wide.WD, 1) Wide.UsersWorkspaces = strings.Replace(Wide.UsersWorkspaces, "${home}", home, 1) if "" != confUsersWorkspaces { Wide.UsersWorkspaces = confUsersWorkspaces @@ -238,7 +232,6 @@ func initWide(confPath, confUsers, confServer, confLogLevel, confPlayground stri } } - // Server if "" != confServer { Wide.Server = confServer @@ -376,8 +369,7 @@ func UpdateCustomizedConf(userId string) { os.Exit(-1) } - wd := util.OS.Pwd() - dir := filepath.Clean(wd + "/static/user/" + u.Id) + dir := filepath.Clean(Wide.UsersWorkspaces + "/" + userId + "/static/") if err := os.MkdirAll(dir, 0755); nil != err { logger.Error(err) diff --git a/main.go b/main.go index 5292c82..5b05bf7 100644 --- a/main.go +++ b/main.go @@ -105,8 +105,8 @@ func main() { // workspaces for _, user := range conf.Users { - http.Handle("/workspace/"+user.Name+"/", - http.StripPrefix("/workspace/"+user.Name+"/", http.FileServer(http.Dir(user.WorkspacePath())))) + http.Handle("/workspace/"+user.Id+"/", + http.StripPrefix("/workspace/"+user.Id+"/", http.FileServer(http.Dir(user.WorkspacePath())))) } // session