FAQ 文档
This commit is contained in:
parent
ec493adffa
commit
8e6583648b
22
conf/wide.go
22
conf/wide.go
|
@ -17,6 +17,7 @@ import (
|
||||||
type User struct {
|
type User struct {
|
||||||
Name string
|
Name string
|
||||||
Password string
|
Password string
|
||||||
|
Workspace string // 指定了该用户的 GOPATH 路径
|
||||||
}
|
}
|
||||||
|
|
||||||
type conf struct {
|
type conf struct {
|
||||||
|
@ -30,24 +31,27 @@ type conf struct {
|
||||||
StaticPath string
|
StaticPath string
|
||||||
MaxProcs int
|
MaxProcs int
|
||||||
RuntimeMode string
|
RuntimeMode string
|
||||||
Workspace string
|
Pwd string
|
||||||
UserWorkspaces string
|
|
||||||
Users []User
|
Users []User
|
||||||
}
|
}
|
||||||
|
|
||||||
var Wide conf
|
var Wide conf
|
||||||
var rawWide conf
|
var rawWide conf
|
||||||
|
|
||||||
func (this *conf) GetWorkspace() string {
|
// 获取 username 指定的用户的工作空间路径.
|
||||||
return filepath.FromSlash(this.Workspace)
|
func (this *conf) GetUserWorkspace(username string) string {
|
||||||
|
for _, user := range Wide.Users {
|
||||||
|
if user.Name == username {
|
||||||
|
ret := strings.Replace(user.Workspace, "{Pwd}", Wide.Pwd, 1)
|
||||||
|
return filepath.FromSlash(ret)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *conf) GetUserWorkspace(username string) string {
|
return ""
|
||||||
return filepath.FromSlash(this.UserWorkspaces) + string(os.PathSeparator) + username
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Save() bool {
|
func Save() bool {
|
||||||
// 可变部分
|
// 只有 Users 是可以通过界面修改的,其他属性只能手工维护 wide.json 配置文件
|
||||||
rawWide.Users = Wide.Users
|
rawWide.Users = Wide.Users
|
||||||
|
|
||||||
// 原始配置文件内容
|
// 原始配置文件内容
|
||||||
|
@ -99,10 +103,8 @@ func Load() {
|
||||||
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))]
|
||||||
|
Wide.Pwd = pwd
|
||||||
glog.V(3).Infof("pwd [%s]", 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))
|
glog.V(3).Info("Conf: \n" + string(bytes))
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,12 +9,12 @@
|
||||||
"StaticPath": "",
|
"StaticPath": "",
|
||||||
"MaxProcs": 4,
|
"MaxProcs": 4,
|
||||||
"RuntimeMode": "dev",
|
"RuntimeMode": "dev",
|
||||||
"Workspace": "{pwd}/data/workspace",
|
"Pwd": "{pwd}",
|
||||||
"UserWorkspaces": "{pwd}/data/user_workspaces",
|
|
||||||
"Users": [
|
"Users": [
|
||||||
{
|
{
|
||||||
"Name": "admin",
|
"Name": "admin",
|
||||||
"Password": "admin"
|
"Password": "admin",
|
||||||
|
"Workspace": "{Pwd}/data/user_workspaces/admin"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Wide - 常见问题与解答</title>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>常见问题与解答</h1>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><b>默认用户是?</b></li>
|
||||||
|
<p>默认用户是 admin 用户。用户名:admin,密码:admin。</p>
|
||||||
|
|
||||||
|
<li><b>什么是工作空间?</b></li>
|
||||||
|
<p>
|
||||||
|
工作空间是当前用户的 $GOPATH 路径指定的目录,一个用户只能有一个工作空间。
|
||||||
|
例如 admin 用户的工作空间默认路径是 {wide}/data/user_workspaces/admin/,可以在 wide.json 中配置。
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<li><b>wide.json 是什么?</b></li>
|
||||||
|
<p>
|
||||||
|
wide.json 是 Wide 的配置文件,路径是 {wide}/conf/wide.json。Wide 的所有配置(例如端口、工作空间、用户帐号、用户选项等)都是保存在这个文件中的。
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
如果 Wide 是个人使用,那么默认的配置应该可以很好的工作,不需要修改任何地方。
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<li><b>如何才能使用已有 $GOPATH?比如我的 $GOPATH 是 D:\\GoGoGo,我要如何才能使用这个目录作为 admin 用户的工作空间?</b></li>
|
||||||
|
<p>
|
||||||
|
修改 wide.json 中 admin 用户的 Workspace,将其从默认的 "{pwd}/data/user_workspaces/admin" 改为 "D:\\GoGoGo"。
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
$GOPATH 是可以通过路径分隔符(Linux 下是 :,Windows 下是 ;)配置多个路径的,但我们不建议您这样配置,因为多个多个目录会造成构建/代码补全等功能的性能下降。
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<li><b>文件树里的 Go API 目录是什么?</b></li>
|
||||||
|
<p>
|
||||||
|
该目录是读取 $GOROOT/src/pkg 生成的,方便用户查看 Go API 源代码。
|
||||||
|
在该目录下是不允许新建、编辑、删除文件的。
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<li><b>如何配置多用户?</b></li>
|
||||||
|
<p>
|
||||||
|
修改 wide.json 中的 Users 数组,按照默认用户的格式(用户名、密码等)添加。
|
||||||
|
</p>
|
||||||
|
</ul>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -33,5 +33,7 @@
|
||||||
<li><a href="editor.html">编辑器</a></li>
|
<li><a href="editor.html">编辑器</a></li>
|
||||||
<li><a href="keyboard_shortcuts.html">键盘快捷键</a></li>
|
<li><a href="keyboard_shortcuts.html">键盘快捷键</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
<h2><a href="faq.html">FAQ</a></h2>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -13,18 +13,7 @@
|
||||||
|
|
||||||
<h2>工作空间</h2>
|
<h2>工作空间</h2>
|
||||||
<p>
|
<p>
|
||||||
一个工作空间由下面几个部分组成:
|
Wide 的工作空间就是 Go 中的 <a href="https://golang.org/doc/code.html#Workspaces" target="_blank">workspaces</a>,每个用户的工作空间路径可在 wide.json 中进行配置。
|
||||||
</p>
|
|
||||||
<ul>
|
|
||||||
<li>源代码仓库:data/user_workspaces/{user}/src</li>
|
|
||||||
<li>GOPATH:data/user_workspaces/{user}</li>
|
|
||||||
</ul>
|
|
||||||
<p>
|
|
||||||
这和 golang 本身 <a href="https://golang.org/doc/code.html#Workspaces" target="_blank">workspaces</a> 的设计保持一致:每个用户的 GOPATH 指定了其工作空间的路径。
|
|
||||||
</p>
|
|
||||||
<h2>版本控制</h2>
|
|
||||||
<p>
|
|
||||||
使用 git 作为源码版本控制系统,data/workspace/src 是主库,每个用户的源码仓库都克隆自主库。
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h2>运行时</h2>
|
<h2>运行时</h2>
|
||||||
|
|
|
@ -114,12 +114,7 @@ func AutocompleteHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
userLib := userWorkspace + string(os.PathSeparator) + "pkg" + string(os.PathSeparator) +
|
userLib := userWorkspace + string(os.PathSeparator) + "pkg" + string(os.PathSeparator) +
|
||||||
runtime.GOOS + "_" + runtime.GOARCH
|
runtime.GOOS + "_" + runtime.GOARCH
|
||||||
|
|
||||||
masterWorkspace := conf.Wide.Workspace
|
libPath := userLib
|
||||||
//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
|
|
||||||
//glog.Infof("gocode set lib-path %s", libPath)
|
//glog.Infof("gocode set lib-path %s", libPath)
|
||||||
|
|
||||||
// FIXME: 使用 gocode set lib-path 在多工作空间环境下肯定是有问题的,需要考虑其他实现方式
|
// FIXME: 使用 gocode set lib-path 在多工作空间环境下肯定是有问题的,需要考虑其他实现方式
|
||||||
|
|
6
main.go
6
main.go
|
@ -21,7 +21,9 @@ import (
|
||||||
// Wide 中唯一一个 init 函数.
|
// Wide 中唯一一个 init 函数.
|
||||||
func init() {
|
func init() {
|
||||||
flag.Set("logtostderr", "true")
|
flag.Set("logtostderr", "true")
|
||||||
flag.Set("v", "1")
|
flag.Set("v", "5")
|
||||||
|
|
||||||
|
conf.Load()
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
}
|
}
|
||||||
|
@ -61,8 +63,6 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
conf.Load()
|
|
||||||
|
|
||||||
runtime.GOMAXPROCS(conf.Wide.MaxProcs)
|
runtime.GOMAXPROCS(conf.Wide.MaxProcs)
|
||||||
|
|
||||||
defer glog.Flush()
|
defer glog.Flush()
|
||||||
|
|
|
@ -51,11 +51,11 @@ func InitGitRepos(w http.ResponseWriter, r *http.Request) {
|
||||||
session, _ := Session.Get(r, "wide-session")
|
session, _ := Session.Get(r, "wide-session")
|
||||||
|
|
||||||
username := session.Values["username"].(string)
|
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
|
// 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 {
|
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)
|
conf.Wide.Users = append(conf.Wide.Users, newUser)
|
||||||
|
|
||||||
if !conf.Save() {
|
if !conf.Save() {
|
||||||
|
|
Loading…
Reference in New Issue