diff --git a/conf/wide.go b/conf/wide.go index 42eb8ef..dfe670d 100644 --- a/conf/wide.go +++ b/conf/wide.go @@ -17,6 +17,9 @@ import ( "github.com/golang/glog" ) +// 系统文件路径分隔符. +const PathSeparator = string(os.PathSeparator) + // 最后一次会话内容结构. type LatestSessionContent struct { FileTree []string // 文件树展开的路径集 @@ -150,25 +153,25 @@ func getGOBIN() string { // $GOBIN/ ret := os.Getenv("GOBIN") if "" != ret { - return ret + string(os.PathSeparator) + return ret + PathSeparator } // $GOPATH/bin/$GOOS_$GOARCH/ - ret = os.Getenv("GOPATH") + string(os.PathSeparator) + "bin" + string(os.PathSeparator) + + ret = os.Getenv("GOPATH") + PathSeparator + "bin" + PathSeparator + os.Getenv("GOOS") + "_" + os.Getenv("GOARCH") if isExist(ret) { - return ret + string(os.PathSeparator) + return ret + PathSeparator } // $GOPATH/bin/{runtime.GOOS}_{runtime.GOARCH}/ - ret = os.Getenv("GOPATH") + string(os.PathSeparator) + "bin" + string(os.PathSeparator) + + ret = os.Getenv("GOPATH") + PathSeparator + "bin" + PathSeparator + runtime.GOOS + "_" + runtime.GOARCH if isExist(ret) { - return ret + string(os.PathSeparator) + return ret + PathSeparator } // $GOPATH/bin/ - return os.Getenv("GOPATH") + string(os.PathSeparator) + "bin" + string(os.PathSeparator) + return os.Getenv("GOPATH") + PathSeparator + "bin" + PathSeparator } // 保存 Wide 配置. @@ -227,7 +230,7 @@ func Load() { // 获取当前执行路径 file, _ := exec.LookPath(os.Args[0]) pwd, _ := filepath.Abs(file) - pwd = pwd[:strings.LastIndex(pwd, string(os.PathSeparator))] + pwd = pwd[:strings.LastIndex(pwd, PathSeparator)] Wide.Pwd = pwd glog.V(3).Infof("pwd [%s]", pwd) diff --git a/conf/wide.json b/conf/wide.json index 66248d9..92138e2 100644 --- a/conf/wide.json +++ b/conf/wide.json @@ -16,9 +16,14 @@ "Password": "admin", "Workspace": "{pwd}/data/user_workspaces/admin", "LatestSessionContent": { - "FileTree": [], - "Files": [], - "CurrentFile": "" + "FileTree": [ + "/home/daniel/gogogo/src/github.com/b3log/wide/data/user_workspaces/admin/src/mytest", + "/home/daniel/gogogo/src/github.com/b3log/wide/data/user_workspaces/admin/src/mytest/time" + ], + "Files": [ + "/home/daniel/gogogo/src/github.com/b3log/wide/data/user_workspaces/admin/src/mytest/time/main.go" + ], + "CurrentFile": "/home/daniel/gogogo/src/github.com/b3log/wide/data/user_workspaces/admin/src/mytest/time/main.go" } } ] diff --git a/editor/editors.go b/editor/editors.go index 221ade6..077a93b 100644 --- a/editor/editors.go +++ b/editor/editors.go @@ -126,7 +126,7 @@ func AutocompleteHandler(w http.ResponseWriter, r *http.Request) { userWorkspace := conf.Wide.GetUserWorkspace(username) //glog.Infof("User [%s] workspace [%s]", username, userWorkspace) - userLib := userWorkspace + string(os.PathSeparator) + "pkg" + string(os.PathSeparator) + + userLib := userWorkspace + conf.PathSeparator + "pkg" + conf.PathSeparator + runtime.GOOS + "_" + runtime.GOARCH libPath := userLib @@ -175,8 +175,8 @@ func GetExprInfoHandler(w http.ResponseWriter, r *http.Request) { } path := args["path"].(string) - curDir := path[:strings.LastIndex(path, string(os.PathSeparator))] - filename := path[strings.LastIndex(path, string(os.PathSeparator))+1:] + curDir := path[:strings.LastIndex(path, conf.PathSeparator)] + filename := path[strings.LastIndex(path, conf.PathSeparator)+1:] fout, err := os.Create(path) @@ -249,8 +249,8 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) { } path := args["path"].(string) - curDir := path[:strings.LastIndex(path, string(os.PathSeparator))] - filename := path[strings.LastIndex(path, string(os.PathSeparator))+1:] + curDir := path[:strings.LastIndex(path, conf.PathSeparator)] + filename := path[strings.LastIndex(path, conf.PathSeparator)+1:] fout, err := os.Create(path) @@ -332,8 +332,8 @@ func FindUsagesHandler(w http.ResponseWriter, r *http.Request) { } filePath := args["path"].(string) - curDir := filePath[:strings.LastIndex(filePath, string(os.PathSeparator))] - filename := filePath[strings.LastIndex(filePath, string(os.PathSeparator))+1:] + curDir := filePath[:strings.LastIndex(filePath, conf.PathSeparator)] + filename := filePath[strings.LastIndex(filePath, conf.PathSeparator)+1:] fout, err := os.Create(filePath) diff --git a/file/files.go b/file/files.go index 5d066d1..7e3edbf 100644 --- a/file/files.go +++ b/file/files.go @@ -45,12 +45,12 @@ func GetFiles(w http.ResponseWriter, r *http.Request) { session, _ := session.HTTPSession.Get(r, "wide-session") username := session.Values["username"].(string) - userSrc := conf.Wide.GetUserWorkspace(username) + string(os.PathSeparator) + "src" + userSrc := conf.Wide.GetUserWorkspace(username) + conf.PathSeparator + "src" root := FileNode{Name: "projects", Path: userSrc, IconSkin: "ico-ztree-dir ", Type: "d", FileNodes: []*FileNode{}} // 构造 Go API 节点 - apiPath := runtime.GOROOT() + string(os.PathSeparator) + "src" + string(os.PathSeparator) + "pkg" + apiPath := runtime.GOROOT() + conf.PathSeparator + "src" + conf.PathSeparator + "pkg" apiNode := FileNode{Name: "Go API", Path: apiPath, FileNodes: []*FileNode{}} goapiBuildOKSignal := make(chan bool) @@ -423,8 +423,8 @@ func removeFile(path string) bool { // 在 dir 指定的目录(包含子目录)中的 extension 指定后缀的文件中搜索包含 text 文本的文件,类似 grep/findstr 命令. func search(dir, extension, text string, snippets []*Snippet) []*Snippet { - if !strings.HasSuffix(dir, string(os.PathSeparator)) { - dir += string(os.PathSeparator) + if !strings.HasSuffix(dir, conf.PathSeparator) { + dir += conf.PathSeparator } f, _ := os.Open(dir) diff --git a/output/outputs.go b/output/outputs.go index a4f910e..ed30f81 100644 --- a/output/outputs.go +++ b/output/outputs.go @@ -73,7 +73,7 @@ func RunHandler(w http.ResponseWriter, r *http.Request) { } filePath := args["executable"].(string) - curDir := filePath[:strings.LastIndex(filePath, string(os.PathSeparator))] + curDir := filePath[:strings.LastIndex(filePath, conf.PathSeparator)] cmd := exec.Command(filePath) cmd.Dir = curDir @@ -183,7 +183,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { sid := args["sid"].(string) filePath := args["file"].(string) - curDir := filePath[:strings.LastIndex(filePath, string(os.PathSeparator))] + curDir := filePath[:strings.LastIndex(filePath, conf.PathSeparator)] fout, err := os.Create(filePath) @@ -219,7 +219,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { glog.V(5).Infof("go build -o %s %s", executable, filePath) - executable = curDir + string(os.PathSeparator) + executable + executable = curDir + conf.PathSeparator + executable // 先把可执行文件删了 err = os.RemoveAll(executable) @@ -370,7 +370,7 @@ func GoInstallHandler(w http.ResponseWriter, r *http.Request) { sid := args["sid"].(string) filePath := args["file"].(string) - curDir := filePath[:strings.LastIndex(filePath, string(os.PathSeparator))] + curDir := filePath[:strings.LastIndex(filePath, conf.PathSeparator)] fout, err := os.Create(filePath) @@ -519,7 +519,7 @@ func GoGetHandler(w http.ResponseWriter, r *http.Request) { sid := args["sid"].(string) filePath := args["file"].(string) - curDir := filePath[:strings.LastIndex(filePath, string(os.PathSeparator))] + curDir := filePath[:strings.LastIndex(filePath, conf.PathSeparator)] cmd := exec.Command("go", "get") cmd.Dir = curDir diff --git a/session/users.go b/session/users.go index d3c5ee7..2d829f8 100644 --- a/session/users.go +++ b/session/users.go @@ -5,7 +5,6 @@ package session import ( "encoding/json" "net/http" - "os" "github.com/b3log/wide/conf" "github.com/b3log/wide/util" @@ -52,7 +51,7 @@ func InitGitRepos(w http.ResponseWriter, r *http.Request) { session, _ := HTTPSession.Get(r, "wide-session") username := session.Values["username"].(string) - userRepos := conf.Wide.GetUserWorkspace(username) + string(os.PathSeparator) + "src" + userRepos := conf.Wide.GetUserWorkspace(username) + conf.PathSeparator + "src" glog.Info(userRepos)