修复文件树异步构建问题
This commit is contained in:
parent
7c69764aed
commit
f5ff038910
|
@ -33,25 +33,25 @@ func GetFiles(w http.ResponseWriter, r *http.Request) {
|
||||||
// 构造 Go API 节点
|
// 构造 Go API 节点
|
||||||
apiPath := runtime.GOROOT() + string(os.PathSeparator) + "src" + string(os.PathSeparator) + "pkg"
|
apiPath := runtime.GOROOT() + string(os.PathSeparator) + "src" + string(os.PathSeparator) + "pkg"
|
||||||
apiNode := FileNode{Name: "Go API", Path: apiPath, FileNodes: []*FileNode{}}
|
apiNode := FileNode{Name: "Go API", Path: apiPath, FileNodes: []*FileNode{}}
|
||||||
|
|
||||||
|
goapiBuildOKSignal := make(chan bool)
|
||||||
go func() {
|
go func() {
|
||||||
fio, _ := os.Lstat(apiPath)
|
|
||||||
if fio.IsDir() {
|
|
||||||
apiNode.Type = "d"
|
apiNode.Type = "d"
|
||||||
// TOOD: Go API 用另外的样式
|
// TOOD: Go API 用另外的样式
|
||||||
apiNode.IconSkin = "ico-ztree-dir "
|
apiNode.IconSkin = "ico-ztree-dir "
|
||||||
|
|
||||||
walk(apiPath, &apiNode)
|
walk(apiPath, &apiNode)
|
||||||
} else {
|
|
||||||
apiNode.Type = "f"
|
|
||||||
ext := filepath.Ext(apiPath)
|
|
||||||
|
|
||||||
apiNode.IconSkin = getIconSkin(ext)
|
// 放行信号
|
||||||
apiNode.Mode = getEditorMode(ext)
|
close(goapiBuildOKSignal)
|
||||||
}
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// 构造用户工作空间文件树
|
// 构造用户工作空间文件树
|
||||||
walk(userSrc, &root)
|
walk(userSrc, &root)
|
||||||
|
|
||||||
|
// 等待放行
|
||||||
|
<-goapiBuildOKSignal
|
||||||
|
|
||||||
// 添加 Go API 节点
|
// 添加 Go API 节点
|
||||||
root.FileNodes = append(root.FileNodes, &apiNode)
|
root.FileNodes = append(root.FileNodes, &apiNode)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue