diff --git a/editor/editors.go b/editor/editors.go index 6b62e71..be017dd 100644 --- a/editor/editors.go +++ b/editor/editors.go @@ -329,12 +329,11 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) { cursorCh, _ := strconv.Atoi(found[strings.LastIndex(found, ":")+1:]) data := map[string]interface{}{} + result.Data = &data data["path"] = filepath.ToSlash(path) data["cursorLine"] = cursorLine data["cursorCh"] = cursorCh - - result.Data = data } // FindUsagesHandler handles request of finding usages. diff --git a/editor/formatter.go b/editor/formatter.go index 9bfd797..337e876 100644 --- a/editor/formatter.go +++ b/editor/formatter.go @@ -79,6 +79,8 @@ func GoFmtHandler(w http.ResponseWriter, r *http.Request) { } data := map[string]interface{}{} + result.Data = &data + data["code"] = code result.Data = data @@ -100,8 +102,6 @@ func GoFmtHandler(w http.ResponseWriter, r *http.Request) { code = string(output) data["code"] = code - result.Data = data - fout, err = os.Create(filePath) fout.WriteString(code) if err := fout.Close(); nil != err { diff --git a/file/files.go b/file/files.go index bec9deb..804d238 100644 --- a/file/files.go +++ b/file/files.go @@ -193,6 +193,7 @@ func GetFileHandler(w http.ResponseWriter, r *http.Request) { } data := map[string]interface{}{} + result.Data = &data buf, _ := ioutil.ReadFile(path) @@ -227,8 +228,6 @@ func GetFileHandler(w http.ResponseWriter, r *http.Request) { data["content"] = content data["path"] = path } - - result.Data = data } // SaveFileHandler handles request of saving file. diff --git a/file/outline.go b/file/outline.go index 82e2558..8ca7804 100755 --- a/file/outline.go +++ b/file/outline.go @@ -57,6 +57,8 @@ func GetOutlineHandler(w http.ResponseWriter, r *http.Request) { } data := map[string]interface{}{} + result.Data = &data + // ast.Print(fset, f) line, ch := getCursor(code, int(f.Name.Pos())) @@ -129,8 +131,6 @@ func GetOutlineHandler(w http.ResponseWriter, r *http.Request) { data["structDecls"] = structDecls data["interfaceDecls"] = interfaceDecls data["typeDecls"] = typeDecls - - result.Data = data } // getCursor calculates the cursor position (line, ch) by the specified offset. diff --git a/playground/build.go b/playground/build.go index 2b9bf5d..3adf3fc 100644 --- a/playground/build.go +++ b/playground/build.go @@ -56,6 +56,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { } data := map[string]interface{}{} + result.Data = &data executable := filepath.Clean(conf.Wide.Playground + "/" + strings.Replace(fileName, ".go", suffix, -1)) @@ -71,6 +72,4 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { } data["executable"] = executable - - result.Data = data } diff --git a/playground/file.go b/playground/file.go index 6272471..912bb68 100644 --- a/playground/file.go +++ b/playground/file.go @@ -73,6 +73,7 @@ func SaveHandler(w http.ResponseWriter, r *http.Request) { } data := map[string]interface{}{} + result.Data = &data data["code"] = code @@ -93,8 +94,6 @@ func SaveHandler(w http.ResponseWriter, r *http.Request) { return } - - result.Data = data } // ShortURLHandler handles request of short URL. diff --git a/static/js/playground.js b/static/js/playground.js index 1d1201e..890ea15 100644 --- a/static/js/playground.js +++ b/static/js/playground.js @@ -456,7 +456,7 @@ var playground = { data: JSON.stringify(request), dataType: "json", success: function (result) { - // console.log(data); + console.log(result); var data = result.data;