路径分隔符重构
This commit is contained in:
parent
93f1e7e2f2
commit
4a2eaef30f
17
conf/wide.go
17
conf/wide.go
|
@ -17,6 +17,9 @@ import (
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 系统文件路径分隔符.
|
||||||
|
const PathSeparator = string(os.PathSeparator)
|
||||||
|
|
||||||
// 最后一次会话内容结构.
|
// 最后一次会话内容结构.
|
||||||
type LatestSessionContent struct {
|
type LatestSessionContent struct {
|
||||||
FileTree []string // 文件树展开的路径集
|
FileTree []string // 文件树展开的路径集
|
||||||
|
@ -150,25 +153,25 @@ func getGOBIN() string {
|
||||||
// $GOBIN/
|
// $GOBIN/
|
||||||
ret := os.Getenv("GOBIN")
|
ret := os.Getenv("GOBIN")
|
||||||
if "" != ret {
|
if "" != ret {
|
||||||
return ret + string(os.PathSeparator)
|
return ret + PathSeparator
|
||||||
}
|
}
|
||||||
|
|
||||||
// $GOPATH/bin/$GOOS_$GOARCH/
|
// $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")
|
os.Getenv("GOOS") + "_" + os.Getenv("GOARCH")
|
||||||
if isExist(ret) {
|
if isExist(ret) {
|
||||||
return ret + string(os.PathSeparator)
|
return ret + PathSeparator
|
||||||
}
|
}
|
||||||
|
|
||||||
// $GOPATH/bin/{runtime.GOOS}_{runtime.GOARCH}/
|
// $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
|
runtime.GOOS + "_" + runtime.GOARCH
|
||||||
if isExist(ret) {
|
if isExist(ret) {
|
||||||
return ret + string(os.PathSeparator)
|
return ret + PathSeparator
|
||||||
}
|
}
|
||||||
|
|
||||||
// $GOPATH/bin/
|
// $GOPATH/bin/
|
||||||
return os.Getenv("GOPATH") + string(os.PathSeparator) + "bin" + string(os.PathSeparator)
|
return os.Getenv("GOPATH") + PathSeparator + "bin" + PathSeparator
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保存 Wide 配置.
|
// 保存 Wide 配置.
|
||||||
|
@ -227,7 +230,7 @@ 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, PathSeparator)]
|
||||||
Wide.Pwd = pwd
|
Wide.Pwd = pwd
|
||||||
glog.V(3).Infof("pwd [%s]", pwd)
|
glog.V(3).Infof("pwd [%s]", pwd)
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,14 @@
|
||||||
"Password": "admin",
|
"Password": "admin",
|
||||||
"Workspace": "{pwd}/data/user_workspaces/admin",
|
"Workspace": "{pwd}/data/user_workspaces/admin",
|
||||||
"LatestSessionContent": {
|
"LatestSessionContent": {
|
||||||
"FileTree": [],
|
"FileTree": [
|
||||||
"Files": [],
|
"/home/daniel/gogogo/src/github.com/b3log/wide/data/user_workspaces/admin/src/mytest",
|
||||||
"CurrentFile": ""
|
"/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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -126,7 +126,7 @@ func AutocompleteHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
userWorkspace := conf.Wide.GetUserWorkspace(username)
|
userWorkspace := conf.Wide.GetUserWorkspace(username)
|
||||||
|
|
||||||
//glog.Infof("User [%s] workspace [%s]", username, userWorkspace)
|
//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
|
runtime.GOOS + "_" + runtime.GOARCH
|
||||||
|
|
||||||
libPath := userLib
|
libPath := userLib
|
||||||
|
@ -175,8 +175,8 @@ func GetExprInfoHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
path := args["path"].(string)
|
path := args["path"].(string)
|
||||||
curDir := path[:strings.LastIndex(path, string(os.PathSeparator))]
|
curDir := path[:strings.LastIndex(path, conf.PathSeparator)]
|
||||||
filename := path[strings.LastIndex(path, string(os.PathSeparator))+1:]
|
filename := path[strings.LastIndex(path, conf.PathSeparator)+1:]
|
||||||
|
|
||||||
fout, err := os.Create(path)
|
fout, err := os.Create(path)
|
||||||
|
|
||||||
|
@ -249,8 +249,8 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
path := args["path"].(string)
|
path := args["path"].(string)
|
||||||
curDir := path[:strings.LastIndex(path, string(os.PathSeparator))]
|
curDir := path[:strings.LastIndex(path, conf.PathSeparator)]
|
||||||
filename := path[strings.LastIndex(path, string(os.PathSeparator))+1:]
|
filename := path[strings.LastIndex(path, conf.PathSeparator)+1:]
|
||||||
|
|
||||||
fout, err := os.Create(path)
|
fout, err := os.Create(path)
|
||||||
|
|
||||||
|
@ -332,8 +332,8 @@ func FindUsagesHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
filePath := args["path"].(string)
|
filePath := args["path"].(string)
|
||||||
curDir := filePath[:strings.LastIndex(filePath, string(os.PathSeparator))]
|
curDir := filePath[:strings.LastIndex(filePath, conf.PathSeparator)]
|
||||||
filename := filePath[strings.LastIndex(filePath, string(os.PathSeparator))+1:]
|
filename := filePath[strings.LastIndex(filePath, conf.PathSeparator)+1:]
|
||||||
|
|
||||||
fout, err := os.Create(filePath)
|
fout, err := os.Create(filePath)
|
||||||
|
|
||||||
|
|
|
@ -45,12 +45,12 @@ func GetFiles(w http.ResponseWriter, r *http.Request) {
|
||||||
session, _ := session.HTTPSession.Get(r, "wide-session")
|
session, _ := session.HTTPSession.Get(r, "wide-session")
|
||||||
|
|
||||||
username := session.Values["username"].(string)
|
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{}}
|
root := FileNode{Name: "projects", Path: userSrc, IconSkin: "ico-ztree-dir ", Type: "d", FileNodes: []*FileNode{}}
|
||||||
|
|
||||||
// 构造 Go API 节点
|
// 构造 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{}}
|
apiNode := FileNode{Name: "Go API", Path: apiPath, FileNodes: []*FileNode{}}
|
||||||
|
|
||||||
goapiBuildOKSignal := make(chan bool)
|
goapiBuildOKSignal := make(chan bool)
|
||||||
|
@ -423,8 +423,8 @@ func removeFile(path string) bool {
|
||||||
|
|
||||||
// 在 dir 指定的目录(包含子目录)中的 extension 指定后缀的文件中搜索包含 text 文本的文件,类似 grep/findstr 命令.
|
// 在 dir 指定的目录(包含子目录)中的 extension 指定后缀的文件中搜索包含 text 文本的文件,类似 grep/findstr 命令.
|
||||||
func search(dir, extension, text string, snippets []*Snippet) []*Snippet {
|
func search(dir, extension, text string, snippets []*Snippet) []*Snippet {
|
||||||
if !strings.HasSuffix(dir, string(os.PathSeparator)) {
|
if !strings.HasSuffix(dir, conf.PathSeparator) {
|
||||||
dir += string(os.PathSeparator)
|
dir += conf.PathSeparator
|
||||||
}
|
}
|
||||||
|
|
||||||
f, _ := os.Open(dir)
|
f, _ := os.Open(dir)
|
||||||
|
|
|
@ -73,7 +73,7 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
filePath := args["executable"].(string)
|
filePath := args["executable"].(string)
|
||||||
curDir := filePath[:strings.LastIndex(filePath, string(os.PathSeparator))]
|
curDir := filePath[:strings.LastIndex(filePath, conf.PathSeparator)]
|
||||||
|
|
||||||
cmd := exec.Command(filePath)
|
cmd := exec.Command(filePath)
|
||||||
cmd.Dir = curDir
|
cmd.Dir = curDir
|
||||||
|
@ -183,7 +183,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
sid := args["sid"].(string)
|
sid := args["sid"].(string)
|
||||||
|
|
||||||
filePath := args["file"].(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)
|
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)
|
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)
|
err = os.RemoveAll(executable)
|
||||||
|
@ -370,7 +370,7 @@ func GoInstallHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
sid := args["sid"].(string)
|
sid := args["sid"].(string)
|
||||||
|
|
||||||
filePath := args["file"].(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)
|
fout, err := os.Create(filePath)
|
||||||
|
|
||||||
|
@ -519,7 +519,7 @@ func GoGetHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
sid := args["sid"].(string)
|
sid := args["sid"].(string)
|
||||||
|
|
||||||
filePath := args["file"].(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 := exec.Command("go", "get")
|
||||||
cmd.Dir = curDir
|
cmd.Dir = curDir
|
||||||
|
|
|
@ -5,7 +5,6 @@ package session
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/b3log/wide/conf"
|
"github.com/b3log/wide/conf"
|
||||||
"github.com/b3log/wide/util"
|
"github.com/b3log/wide/util"
|
||||||
|
@ -52,7 +51,7 @@ func InitGitRepos(w http.ResponseWriter, r *http.Request) {
|
||||||
session, _ := HTTPSession.Get(r, "wide-session")
|
session, _ := HTTPSession.Get(r, "wide-session")
|
||||||
|
|
||||||
username := session.Values["username"].(string)
|
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)
|
glog.Info(userRepos)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue