diff --git a/conf/wide.go b/conf/wide.go index 91bb597..09491eb 100644 --- a/conf/wide.go +++ b/conf/wide.go @@ -15,8 +15,9 @@ import ( ) type User struct { - Name string - Password string + Name string + Password string + Workspace string // 指定了该用户的 GOPATH 路径 } type conf struct { @@ -30,24 +31,27 @@ type conf struct { StaticPath string MaxProcs int RuntimeMode string - Workspace string - UserWorkspaces string + Pwd string Users []User } var Wide conf var rawWide conf -func (this *conf) GetWorkspace() string { - return filepath.FromSlash(this.Workspace) -} - +// 获取 username 指定的用户的工作空间路径. func (this *conf) GetUserWorkspace(username string) string { - return filepath.FromSlash(this.UserWorkspaces) + string(os.PathSeparator) + username + for _, user := range Wide.Users { + if user.Name == username { + ret := strings.Replace(user.Workspace, "{Pwd}", Wide.Pwd, 1) + return filepath.FromSlash(ret) + } + } + + return "" } func Save() bool { - // 可变部分 + // 只有 Users 是可以通过界面修改的,其他属性只能手工维护 wide.json 配置文件 rawWide.Users = Wide.Users // 原始配置文件内容 @@ -99,10 +103,8 @@ func Load() { file, _ := exec.LookPath(os.Args[0]) pwd, _ := filepath.Abs(file) pwd = pwd[:strings.LastIndex(pwd, string(os.PathSeparator))] + Wide.Pwd = pwd glog.V(3).Infof("pwd [%s]", pwd) - Wide.Workspace = strings.Replace(Wide.Workspace, "{pwd}", pwd, 1) - Wide.UserWorkspaces = strings.Replace(Wide.UserWorkspaces, "{pwd}", pwd, 1) - glog.V(3).Info("Conf: \n" + string(bytes)) } diff --git a/conf/wide.json b/conf/wide.json index 931e5fd..37551b5 100644 --- a/conf/wide.json +++ b/conf/wide.json @@ -9,12 +9,12 @@ "StaticPath": "", "MaxProcs": 4, "RuntimeMode": "dev", - "Workspace": "{pwd}/data/workspace", - "UserWorkspaces": "{pwd}/data/user_workspaces", + "Pwd": "{pwd}", "Users": [ { "Name": "admin", - "Password": "admin" + "Password": "admin", + "Workspace": "{Pwd}/data/user_workspaces/admin" } ] } \ No newline at end of file diff --git a/doc/zh_CN/faq.html b/doc/zh_CN/faq.html new file mode 100644 index 0000000..059b8ab --- /dev/null +++ b/doc/zh_CN/faq.html @@ -0,0 +1,51 @@ + + + + + Wide - 常见问题与解答 + + + +

常见问题与解答

+ + + + diff --git a/doc/zh_CN/index.html b/doc/zh_CN/index.html index 51b2aef..a24f399 100644 --- a/doc/zh_CN/index.html +++ b/doc/zh_CN/index.html @@ -10,7 +10,7 @@

Wide 是一个基于 Web 的 golang 开源 IDE。

- +

动机

特性

@@ -30,8 +30,10 @@

使用指南

+ + +

FAQ

diff --git a/doc/zh_CN/multiplayer.html b/doc/zh_CN/multiplayer.html index b6a6dfb..a0a3ad1 100644 --- a/doc/zh_CN/multiplayer.html +++ b/doc/zh_CN/multiplayer.html @@ -13,20 +13,9 @@

工作空间

- 一个工作空间由下面几个部分组成: + Wide 的工作空间就是 Go 中的 workspaces,每个用户的工作空间路径可在 wide.json 中进行配置。

- -

- 这和 golang 本身 workspaces 的设计保持一致:每个用户的 GOPATH 指定了其工作空间的路径。 -

-

版本控制

-

- 使用 git 作为源码版本控制系统,data/workspace/src 是主库,每个用户的源码仓库都克隆自主库。 -

- +

运行时

用户在运行程序时进程是跑在服务器上的,所以多用户同时运行程序时最常见的问题就是资源冲突(比如网络端口),目前这个问题只能靠用户自行规避。 diff --git a/editor/editors.go b/editor/editors.go index 02f71c7..a359ac1 100644 --- a/editor/editors.go +++ b/editor/editors.go @@ -114,12 +114,7 @@ func AutocompleteHandler(w http.ResponseWriter, r *http.Request) { userLib := userWorkspace + string(os.PathSeparator) + "pkg" + string(os.PathSeparator) + runtime.GOOS + "_" + runtime.GOARCH - masterWorkspace := conf.Wide.Workspace - //glog.Infof("Master workspace [%s]", masterWorkspace) - masterLib := masterWorkspace + string(os.PathSeparator) + "pkg" + string(os.PathSeparator) + - runtime.GOOS + "_" + runtime.GOARCH - - libPath := userLib + string(os.PathListSeparator) + masterLib + libPath := userLib //glog.Infof("gocode set lib-path %s", libPath) // FIXME: 使用 gocode set lib-path 在多工作空间环境下肯定是有问题的,需要考虑其他实现方式 diff --git a/main.go b/main.go index 0a9c47c..175da48 100644 --- a/main.go +++ b/main.go @@ -21,7 +21,9 @@ import ( // Wide 中唯一一个 init 函数. func init() { flag.Set("logtostderr", "true") - flag.Set("v", "1") + flag.Set("v", "5") + + conf.Load() flag.Parse() } @@ -61,8 +63,6 @@ func indexHandler(w http.ResponseWriter, r *http.Request) { } func main() { - conf.Load() - runtime.GOMAXPROCS(conf.Wide.MaxProcs) defer glog.Flush() diff --git a/user/users.go b/user/users.go index 9ce9713..50a3df2 100644 --- a/user/users.go +++ b/user/users.go @@ -51,11 +51,11 @@ func InitGitRepos(w http.ResponseWriter, r *http.Request) { session, _ := Session.Get(r, "wide-session") username := session.Values["username"].(string) - userRepos := conf.Wide.UserWorkspaces + string(os.PathSeparator) + username + string(os.PathSeparator) + "src" + userRepos := conf.Wide.GetUserWorkspace(username) + string(os.PathSeparator) + "src" + + glog.Info(userRepos) // TODO: git clone - - glog.Infof("Git Cloned from [%s] to [%s]", conf.Wide.Workspace+string(os.PathSeparator)+"src", userRepos) } func addUser(username, password string) string { @@ -69,7 +69,8 @@ func addUser(username, password string) string { } } - newUser := conf.User{Name: username, Password: password} + // FIXME: 新建用户时保存工作空间 + newUser := conf.User{Name: username, Password: password, Workspace: ""} conf.Wide.Users = append(conf.Wide.Users, newUser) if !conf.Save() {