This commit is contained in:
parent
fdba27c224
commit
abe5672490
|
@ -82,8 +82,8 @@ func GetFilesHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
username := httpSession.Values["username"].(string)
|
username := httpSession.Values["username"].(string)
|
||||||
|
|
||||||
data := map[string]interface{}{"succ": true}
|
result := util.NewResult()
|
||||||
defer util.RetGzJSON(w, r, data)
|
defer util.RetGzResult(w, r, result)
|
||||||
|
|
||||||
userWorkspace := conf.GetUserWorkspace(username)
|
userWorkspace := conf.GetUserWorkspace(username)
|
||||||
workspaces := filepath.SplitList(userWorkspace)
|
workspaces := filepath.SplitList(userWorkspace)
|
||||||
|
@ -118,7 +118,7 @@ func GetFilesHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
// add Go API node
|
// add Go API node
|
||||||
root.Children = append(root.Children, apiNode)
|
root.Children = append(root.Children, apiNode)
|
||||||
|
|
||||||
data["root"] = root
|
result.Data = root
|
||||||
}
|
}
|
||||||
|
|
||||||
// RefreshDirectoryHandler handles request of refresh a directory of file tree.
|
// RefreshDirectoryHandler handles request of refresh a directory of file tree.
|
||||||
|
|
|
@ -367,7 +367,7 @@ var tree = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
tree.fileTree = $.fn.zTree.init($("#files"), setting, data.root.children);
|
tree.fileTree = $.fn.zTree.init($("#files"), setting, data.data.children);
|
||||||
|
|
||||||
session.restore();
|
session.restore();
|
||||||
}
|
}
|
||||||
|
|
54
util/ret.go
54
util/ret.go
|
@ -51,27 +51,15 @@ func RetResult(w http.ResponseWriter, r *http.Request, res *Result) {
|
||||||
data, err := json.Marshal(res)
|
data, err := json.Marshal(res)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
retLogger.Error(err)
|
retLogger.Error(err)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Write(data)
|
w.Write(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RetJSON writes HTTP response with "Content-Type, application/json".
|
// RetGzResult writes HTTP response with "Content-Type, application/json" and "Content-Encoding, gzip".
|
||||||
func RetJSON(w http.ResponseWriter, r *http.Request, res map[string]interface{}) {
|
func RetGzResult(w http.ResponseWriter, r *http.Request, res *Result) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
|
|
||||||
data, err := json.Marshal(res)
|
|
||||||
if err != nil {
|
|
||||||
retLogger.Error(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Write(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
// RetGzJSON writes HTTP response with "Content-Type, application/json".
|
|
||||||
func RetGzJSON(w http.ResponseWriter, r *http.Request, res map[string]interface{}) {
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.Header().Set("Content-Encoding", "gzip")
|
w.Header().Set("Content-Encoding", "gzip")
|
||||||
|
|
||||||
|
@ -79,6 +67,42 @@ func RetGzJSON(w http.ResponseWriter, r *http.Request, res map[string]interface{
|
||||||
err := json.NewEncoder(gz).Encode(res)
|
err := json.NewEncoder(gz).Encode(res)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
retLogger.Error(err)
|
retLogger.Error(err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = gz.Close()
|
||||||
|
if nil != err {
|
||||||
|
retLogger.Error(err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// RetJSON writes HTTP response with "Content-Type, application/json".
|
||||||
|
func RetJSON(w http.ResponseWriter, r *http.Request, res map[string]interface{}) {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
data, err := json.Marshal(res)
|
||||||
|
if err != nil {
|
||||||
|
retLogger.Error(err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Write(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RetGzJSON writes HTTP response with "Content-Type, application/json" and "Content-Encoding, gzip".
|
||||||
|
func RetGzJSON(w http.ResponseWriter, r *http.Request, res map[string]interface{}) {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.Header().Set("Content-Encoding", "gzip")
|
||||||
|
|
||||||
|
gz := gzip.NewWriter(w)
|
||||||
|
err := json.NewEncoder(gz).Encode(res)
|
||||||
|
if nil != err {
|
||||||
|
retLogger.Error(err)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue