Fix #257
This commit is contained in:
parent
0ee3704a5b
commit
f3dadc4795
|
@ -78,6 +78,11 @@ func GoFmtHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data := map[string]interface{}{}
|
||||||
|
data["code"] = code
|
||||||
|
|
||||||
|
result.Data = data
|
||||||
|
|
||||||
fmt := conf.GetGoFmt(username)
|
fmt := conf.GetGoFmt(username)
|
||||||
|
|
||||||
argv := []string{filePath}
|
argv := []string{filePath}
|
||||||
|
@ -88,13 +93,14 @@ func GoFmtHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if "" == output {
|
if "" == output {
|
||||||
// format error, returns the original content
|
// format error, returns the original content
|
||||||
result.Succ = true
|
result.Succ = true
|
||||||
result.Code = code
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
code = string(output)
|
code = string(output)
|
||||||
result.Code = code
|
data["code"] = code
|
||||||
|
|
||||||
|
result.Data = data
|
||||||
|
|
||||||
fout, err = os.Create(filePath)
|
fout, err = os.Create(filePath)
|
||||||
fout.WriteString(code)
|
fout.WriteString(code)
|
||||||
|
|
|
@ -32,8 +32,8 @@ import (
|
||||||
|
|
||||||
// GoTestHandler handles request of go test.
|
// GoTestHandler handles request of go test.
|
||||||
func GoTestHandler(w http.ResponseWriter, r *http.Request) {
|
func GoTestHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
data := map[string]interface{}{"succ": true}
|
result := util.NewResult()
|
||||||
defer util.RetJSON(w, r, data)
|
defer util.RetResult(w, r, result)
|
||||||
|
|
||||||
httpSession, _ := session.HTTPSession.Get(r, "wide-session")
|
httpSession, _ := session.HTTPSession.Get(r, "wide-session")
|
||||||
if httpSession.IsNew {
|
if httpSession.IsNew {
|
||||||
|
@ -48,7 +48,7 @@ func GoTestHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
data["succ"] = false
|
result.Succ = false
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ func GoTestHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
stdout, err := cmd.StdoutPipe()
|
stdout, err := cmd.StdoutPipe()
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
data["succ"] = false
|
result.Succ = false
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -74,12 +74,12 @@ func GoTestHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
stderr, err := cmd.StderrPipe()
|
stderr, err := cmd.StderrPipe()
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
data["succ"] = false
|
result.Succ = false
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !data["succ"].(bool) {
|
if !result.Succ {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ func GoTestHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
if err := cmd.Start(); nil != err {
|
if err := cmd.Start(); nil != err {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
data["succ"] = false
|
result.Succ = false
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,8 +32,8 @@ import (
|
||||||
|
|
||||||
// GoVetHandler handles request of go vet.
|
// GoVetHandler handles request of go vet.
|
||||||
func GoVetHandler(w http.ResponseWriter, r *http.Request) {
|
func GoVetHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
data := map[string]interface{}{"succ": true}
|
result := util.NewResult()
|
||||||
defer util.RetJSON(w, r, data)
|
defer util.RetResult(w, r, result)
|
||||||
|
|
||||||
httpSession, _ := session.HTTPSession.Get(r, "wide-session")
|
httpSession, _ := session.HTTPSession.Get(r, "wide-session")
|
||||||
if httpSession.IsNew {
|
if httpSession.IsNew {
|
||||||
|
@ -48,7 +48,7 @@ func GoVetHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
data["succ"] = false
|
result.Succ = false
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ func GoVetHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
stdout, err := cmd.StdoutPipe()
|
stdout, err := cmd.StdoutPipe()
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
data["succ"] = false
|
result.Succ = false
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -74,12 +74,12 @@ func GoVetHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
stderr, err := cmd.StderrPipe()
|
stderr, err := cmd.StderrPipe()
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
data["succ"] = false
|
result.Succ = false
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !data["succ"].(bool) {
|
if !result.Succ {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ func GoVetHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
if err := cmd.Start(); nil != err {
|
if err := cmd.Start(); nil != err {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
data["succ"] = false
|
result.Succ = false
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,8 @@ import (
|
||||||
|
|
||||||
// BuildHandler handles request of Playground building.
|
// BuildHandler handles request of Playground building.
|
||||||
func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
data := map[string]interface{}{"succ": true}
|
result := util.NewResult()
|
||||||
defer util.RetJSON(w, r, data)
|
defer util.RetResult(w, r, result)
|
||||||
|
|
||||||
httpSession, _ := session.HTTPSession.Get(r, "wide-session")
|
httpSession, _ := session.HTTPSession.Get(r, "wide-session")
|
||||||
if httpSession.IsNew {
|
if httpSession.IsNew {
|
||||||
|
@ -42,7 +42,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
var args map[string]interface{}
|
var args map[string]interface{}
|
||||||
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
data["succ"] = false
|
result.Succ = false
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -55,18 +55,22 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
suffix = ".exe"
|
suffix = ".exe"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data := map[string]interface{}{}
|
||||||
|
|
||||||
executable := filepath.Clean(conf.Wide.Playground + "/" + strings.Replace(fileName, ".go", suffix, -1))
|
executable := filepath.Clean(conf.Wide.Playground + "/" + strings.Replace(fileName, ".go", suffix, -1))
|
||||||
|
|
||||||
cmd := exec.Command("go", "build", "-o", executable, filePath)
|
cmd := exec.Command("go", "build", "-o", executable, filePath)
|
||||||
|
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
|
|
||||||
data["output"] = template.HTML(string(out))
|
data["output"] = template.HTML(string(out))
|
||||||
|
|
||||||
if nil != err {
|
if nil != err {
|
||||||
data["succ"] = false
|
result.Succ = false
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data["executable"] = executable
|
data["executable"] = executable
|
||||||
|
|
||||||
|
result.Data = data
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,8 +32,8 @@ import (
|
||||||
|
|
||||||
// SaveHandler handles request of Playground code save.
|
// SaveHandler handles request of Playground code save.
|
||||||
func SaveHandler(w http.ResponseWriter, r *http.Request) {
|
func SaveHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
data := map[string]interface{}{"succ": true}
|
result := util.NewResult()
|
||||||
defer util.RetJSON(w, r, data)
|
defer util.RetResult(w, r, result)
|
||||||
|
|
||||||
session, _ := session.HTTPSession.Get(r, "wide-session")
|
session, _ := session.HTTPSession.Get(r, "wide-session")
|
||||||
if session.IsNew {
|
if session.IsNew {
|
||||||
|
@ -45,7 +45,7 @@ func SaveHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
var args map[string]interface{}
|
var args map[string]interface{}
|
||||||
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
data["succ"] = false
|
result.Succ = false
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ func SaveHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
stdin, err := cmd.StdinPipe()
|
stdin, err := cmd.StdinPipe()
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
data["succ"] = false
|
result.Succ = false
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -72,6 +72,8 @@ func SaveHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
code = string(output)
|
code = string(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data := map[string]interface{}{}
|
||||||
|
|
||||||
data["code"] = code
|
data["code"] = code
|
||||||
|
|
||||||
// Step2. generate file name
|
// Step2. generate file name
|
||||||
|
@ -87,16 +89,18 @@ func SaveHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
fout.WriteString(code)
|
fout.WriteString(code)
|
||||||
if err := fout.Close(); nil != err {
|
if err := fout.Close(); nil != err {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
data["succ"] = false
|
result.Succ = false
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result.Data = data
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShortURLHandler handles request of short URL.
|
// ShortURLHandler handles request of short URL.
|
||||||
func ShortURLHandler(w http.ResponseWriter, r *http.Request) {
|
func ShortURLHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
data := map[string]interface{}{"succ": true}
|
result := util.NewResult()
|
||||||
defer util.RetJSON(w, r, data)
|
defer util.RetResult(w, r, result)
|
||||||
|
|
||||||
session, _ := session.HTTPSession.Get(r, "wide-session")
|
session, _ := session.HTTPSession.Get(r, "wide-session")
|
||||||
if session.IsNew {
|
if session.IsNew {
|
||||||
|
@ -108,7 +112,7 @@ func ShortURLHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
var args map[string]interface{}
|
var args map[string]interface{}
|
||||||
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
data["succ"] = false
|
result.Succ = false
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -121,7 +125,7 @@ func ShortURLHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
var response map[string]interface{}
|
var response map[string]interface{}
|
||||||
if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
|
if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
data["succ"] = false
|
result.Succ = false
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -131,5 +135,5 @@ func ShortURLHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
shortURL = response["tinyurl"].(string)
|
shortURL = response["tinyurl"].(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
data["shortURL"] = shortURL
|
result.Data = shortURL
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,20 +40,20 @@ type outputBuf struct {
|
||||||
|
|
||||||
// RunHandler handles request of executing a binary file.
|
// RunHandler handles request of executing a binary file.
|
||||||
func RunHandler(w http.ResponseWriter, r *http.Request) {
|
func RunHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
data := map[string]interface{}{"succ": true}
|
result := util.NewResult()
|
||||||
defer util.RetJSON(w, r, data)
|
defer util.RetResult(w, r, result)
|
||||||
|
|
||||||
var args map[string]interface{}
|
var args map[string]interface{}
|
||||||
|
|
||||||
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
data["succ"] = false
|
result.Succ = false
|
||||||
}
|
}
|
||||||
|
|
||||||
sid := args["sid"].(string)
|
sid := args["sid"].(string)
|
||||||
wSession := session.WideSessions.Get(sid)
|
wSession := session.WideSessions.Get(sid)
|
||||||
if nil == wSession {
|
if nil == wSession {
|
||||||
data["succ"] = false
|
result.Succ = false
|
||||||
}
|
}
|
||||||
|
|
||||||
filePath := args["executable"].(string)
|
filePath := args["executable"].(string)
|
||||||
|
@ -67,13 +67,13 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
stdout, err := cmd.StdoutPipe()
|
stdout, err := cmd.StdoutPipe()
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
data["succ"] = false
|
result.Succ = false
|
||||||
}
|
}
|
||||||
|
|
||||||
stderr, err := cmd.StderrPipe()
|
stderr, err := cmd.StderrPipe()
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
data["succ"] = false
|
result.Succ = false
|
||||||
}
|
}
|
||||||
|
|
||||||
outReader := bufio.NewReader(stdout)
|
outReader := bufio.NewReader(stdout)
|
||||||
|
@ -81,14 +81,14 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
if err := cmd.Start(); nil != err {
|
if err := cmd.Start(); nil != err {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
data["succ"] = false
|
result.Succ = false
|
||||||
}
|
}
|
||||||
|
|
||||||
wsChannel := session.PlaygroundWS[sid]
|
wsChannel := session.PlaygroundWS[sid]
|
||||||
|
|
||||||
channelRet := map[string]interface{}{}
|
channelRet := map[string]interface{}{}
|
||||||
|
|
||||||
if !data["succ"].(bool) {
|
if !result.Succ {
|
||||||
if nil != wsChannel {
|
if nil != wsChannel {
|
||||||
channelRet["cmd"] = "run-done"
|
channelRet["cmd"] = "run-done"
|
||||||
channelRet["output"] = ""
|
channelRet["output"] = ""
|
||||||
|
@ -227,13 +227,13 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// StopHandler handles request of stoping a running process.
|
// StopHandler handles request of stoping a running process.
|
||||||
func StopHandler(w http.ResponseWriter, r *http.Request) {
|
func StopHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
data := map[string]interface{}{"succ": true}
|
result := util.NewResult()
|
||||||
defer util.RetJSON(w, r, data)
|
defer util.RetResult(w, r, result)
|
||||||
|
|
||||||
var args map[string]interface{}
|
var args map[string]interface{}
|
||||||
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
data["succ"] = false
|
result.Succ = false
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -243,7 +243,7 @@ func StopHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
wSession := session.WideSessions.Get(sid)
|
wSession := session.WideSessions.Get(sid)
|
||||||
if nil == wSession {
|
if nil == wSession {
|
||||||
data["succ"] = false
|
result.Succ = false
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,8 +36,8 @@ var logger = log.NewLogger(os.Stdout)
|
||||||
|
|
||||||
// Clone handles request of git clone.
|
// Clone handles request of git clone.
|
||||||
func CloneHandler(w http.ResponseWriter, r *http.Request) {
|
func CloneHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
data := map[string]interface{}{"succ": true}
|
result := util.NewResult()
|
||||||
defer util.RetJSON(w, r, data)
|
defer util.RetResult(w, r, result)
|
||||||
|
|
||||||
httpSession, _ := session.HTTPSession.Get(r, "wide-session")
|
httpSession, _ := session.HTTPSession.Get(r, "wide-session")
|
||||||
if httpSession.IsNew {
|
if httpSession.IsNew {
|
||||||
|
@ -51,7 +51,7 @@ func CloneHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
var args map[string]interface{}
|
var args map[string]interface{}
|
||||||
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
data["succ"] = false
|
result.Succ = false
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ func CloneHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
stdout, err := cmd.StdoutPipe()
|
stdout, err := cmd.StdoutPipe()
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
data["succ"] = false
|
result.Succ = false
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -74,12 +74,12 @@ func CloneHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
stderr, err := cmd.StderrPipe()
|
stderr, err := cmd.StderrPipe()
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
data["succ"] = false
|
result.Succ = false
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !data["succ"].(bool) {
|
if !result.Succ {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ func CloneHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
if err := cmd.Start(); nil != err {
|
if err := cmd.Start(); nil != err {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
data["succ"] = false
|
result.Succ = false
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -281,8 +281,8 @@ func WSHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// SaveContentHandler handles request of session content string.
|
// SaveContentHandler handles request of session content string.
|
||||||
func SaveContentHandler(w http.ResponseWriter, r *http.Request) {
|
func SaveContentHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
data := map[string]interface{}{"succ": true}
|
result := util.NewResult()
|
||||||
defer util.RetJSON(w, r, data)
|
defer util.RetResult(w, r, result)
|
||||||
|
|
||||||
args := struct {
|
args := struct {
|
||||||
Sid string
|
Sid string
|
||||||
|
@ -291,14 +291,14 @@ func SaveContentHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
data["succ"] = false
|
result.Succ = false
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
wSession := WideSessions.Get(args.Sid)
|
wSession := WideSessions.Get(args.Sid)
|
||||||
if nil == wSession {
|
if nil == wSession {
|
||||||
data["succ"] = false
|
result.Succ = false
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,9 +88,8 @@ func PreferenceHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// non-GET request as save request
|
// non-GET request as save request
|
||||||
|
|
||||||
succ := true
|
result := util.NewResult()
|
||||||
data := map[string]interface{}{"succ": &succ}
|
defer util.RetResult(w, r, result)
|
||||||
defer util.RetJSON(w, r, data)
|
|
||||||
|
|
||||||
args := struct {
|
args := struct {
|
||||||
FontFamily string
|
FontFamily string
|
||||||
|
@ -112,7 +111,7 @@ func PreferenceHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
succ = false
|
result.Succ = false
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -146,7 +145,7 @@ func PreferenceHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
user.Lived = now
|
user.Lived = now
|
||||||
user.Updated = now
|
user.Updated = now
|
||||||
|
|
||||||
succ = user.Save()
|
result.Succ = user.Save()
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoginHandler handles request of user login.
|
// LoginHandler handles request of user login.
|
||||||
|
@ -211,8 +210,8 @@ func LoginHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// LogoutHandler handles request of user logout (exit).
|
// LogoutHandler handles request of user logout (exit).
|
||||||
func LogoutHandler(w http.ResponseWriter, r *http.Request) {
|
func LogoutHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
data := map[string]interface{}{"succ": true}
|
result := util.NewResult()
|
||||||
defer util.RetJSON(w, r, data)
|
defer util.RetResult(w, r, result)
|
||||||
|
|
||||||
httpSession, _ := HTTPSession.Get(r, "wide-session")
|
httpSession, _ := HTTPSession.Get(r, "wide-session")
|
||||||
|
|
||||||
|
@ -248,15 +247,14 @@ func SignUpUserHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// non-GET request as add user request
|
// non-GET request as add user request
|
||||||
|
|
||||||
succ := true
|
result := util.NewResult()
|
||||||
data := map[string]interface{}{"succ": &succ}
|
defer util.RetResult(w, r, result)
|
||||||
defer util.RetJSON(w, r, data)
|
|
||||||
|
|
||||||
var args map[string]interface{}
|
var args map[string]interface{}
|
||||||
|
|
||||||
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
succ = false
|
result.Succ = false
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -267,8 +265,8 @@ func SignUpUserHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
msg := addUser(username, password, email)
|
msg := addUser(username, password, email)
|
||||||
if userCreated != msg {
|
if userCreated != msg {
|
||||||
succ = false
|
result.Succ = false
|
||||||
data["msg"] = msg
|
result.Msg = msg
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,8 +156,8 @@ var menu = {
|
||||||
url: config.context + '/logout',
|
url: config.context + '/logout',
|
||||||
data: JSON.stringify(request),
|
data: JSON.stringify(request),
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (data) {
|
success: function (result) {
|
||||||
if (data.succ) {
|
if (result.succ) {
|
||||||
window.location.href = "/login";
|
window.location.href = "/login";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -454,8 +454,8 @@ var menu = {
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: config.context + '/preference',
|
url: config.context + '/preference',
|
||||||
data: JSON.stringify(request),
|
data: JSON.stringify(request),
|
||||||
success: function (data, textStatus, jqXHR) {
|
success: function (result, textStatus, jqXHR) {
|
||||||
if (!data.succ) {
|
if (!result.succ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -334,10 +334,12 @@ var playground = {
|
||||||
url: config.context + '/playground/save',
|
url: config.context + '/playground/save',
|
||||||
data: JSON.stringify(request),
|
data: JSON.stringify(request),
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (data) {
|
success: function (result) {
|
||||||
|
var data = result.data;
|
||||||
|
|
||||||
playground.editor.setValue(data.code);
|
playground.editor.setValue(data.code);
|
||||||
|
|
||||||
if (!data.succ) {
|
if (!result.succ) {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -351,9 +353,9 @@ var playground = {
|
||||||
url: config.context + '/playground/short-url',
|
url: config.context + '/playground/short-url',
|
||||||
data: JSON.stringify(request),
|
data: JSON.stringify(request),
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (data) {
|
success: function (result) {
|
||||||
if (!data.succ) {
|
if (!result.succ) {
|
||||||
console.log(data);
|
console.log(result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,8 +363,8 @@ var playground = {
|
||||||
+ config.label.colon + '</label><a href="'
|
+ config.label.colon + '</label><a href="'
|
||||||
+ url + '" target="_blank">' + url + "</a><br/>";
|
+ url + '" target="_blank">' + url + "</a><br/>";
|
||||||
html += '<label>' + config.label.short_url + config.label.colon
|
html += '<label>' + config.label.short_url + config.label.colon
|
||||||
+ '</label><a href="' + data.shortURL + '" target="_blank">'
|
+ '</label><a href="' + result.data + '" target="_blank">'
|
||||||
+ data.shortURL + '</a><br/>';
|
+ result.data + '</a><br/>';
|
||||||
html += '<label>' + config.label.embeded + config.label.colon
|
html += '<label>' + config.label.embeded + config.label.colon
|
||||||
+ '</label><br/><textarea rows="5" style="width:100%" readonly><iframe style="border:1px solid" src="'
|
+ '</label><br/><textarea rows="5" style="width:100%" readonly><iframe style="border:1px solid" src="'
|
||||||
+ url + '?embed=true" width="99%" height="600"></iframe></textarea>';
|
+ url + '?embed=true" width="99%" height="600"></iframe></textarea>';
|
||||||
|
@ -434,12 +436,13 @@ var playground = {
|
||||||
url: config.context + '/playground/save',
|
url: config.context + '/playground/save',
|
||||||
data: JSON.stringify(request),
|
data: JSON.stringify(request),
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (data) {
|
success: function (result) {
|
||||||
// console.log(data);
|
var data = result.data;
|
||||||
|
|
||||||
playground.editor.setValue(data.code);
|
playground.editor.setValue(data.code);
|
||||||
playground.editor.setCursor(cursor);
|
playground.editor.setCursor(cursor);
|
||||||
|
|
||||||
if (!data.succ) {
|
if (!result.succ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -452,12 +455,14 @@ var playground = {
|
||||||
url: config.context + '/playground/build',
|
url: config.context + '/playground/build',
|
||||||
data: JSON.stringify(request),
|
data: JSON.stringify(request),
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (data) {
|
success: function (result) {
|
||||||
// console.log(data);
|
// console.log(data);
|
||||||
|
|
||||||
|
var data = result.data;
|
||||||
|
|
||||||
$("#output").val(data.output);
|
$("#output").val(data.output);
|
||||||
|
|
||||||
if (!data.succ) {
|
if (!result.succ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -470,7 +475,7 @@ var playground = {
|
||||||
url: config.context + '/playground/run',
|
url: config.context + '/playground/run',
|
||||||
data: JSON.stringify(request),
|
data: JSON.stringify(request),
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (data) {
|
success: function (result) {
|
||||||
// console.log(data);
|
// console.log(data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -497,8 +502,8 @@ var playground = {
|
||||||
url: config.context + '/playground/save',
|
url: config.context + '/playground/save',
|
||||||
data: JSON.stringify(request),
|
data: JSON.stringify(request),
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (data) {
|
success: function (result) {
|
||||||
playground.editor.setValue(data.code);
|
playground.editor.setValue(result.data.code);
|
||||||
playground.editor.setCursor(cursor);
|
playground.editor.setCursor(cursor);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -44,7 +44,7 @@ var session = {
|
||||||
url: config.context + '/session/save',
|
url: config.context + '/session/save',
|
||||||
data: JSON.stringify(request),
|
data: JSON.stringify(request),
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (data) {
|
success: function (result) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, 30000);
|
}, 30000);
|
||||||
|
|
|
@ -201,9 +201,9 @@ var tree = {
|
||||||
url: config.context + '/file/decompress',
|
url: config.context + '/file/decompress',
|
||||||
data: JSON.stringify(request),
|
data: JSON.stringify(request),
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (data) {
|
success: function (result) {
|
||||||
if (!data.succ) {
|
if (!result.succ) {
|
||||||
$("#dialogAlert").dialog("open", data.msg);
|
$("#dialogAlert").dialog("open", result.msg);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -534,8 +534,8 @@ var tree = {
|
||||||
url: config.context + '/file/rename',
|
url: config.context + '/file/rename',
|
||||||
data: JSON.stringify(request),
|
data: JSON.stringify(request),
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (data) {
|
success: function (result) {
|
||||||
if (!data.succ) {
|
if (!result.succ) {
|
||||||
$("#dialogRenamePrompt").dialog("close");
|
$("#dialogRenamePrompt").dialog("close");
|
||||||
bottomGroup.tabs.setCurrent("notification");
|
bottomGroup.tabs.setCurrent("notification");
|
||||||
windows.flowBottom();
|
windows.flowBottom();
|
||||||
|
|
|
@ -117,8 +117,8 @@ var wide = {
|
||||||
url: config.context + '/file/remove',
|
url: config.context + '/file/remove',
|
||||||
data: JSON.stringify(request),
|
data: JSON.stringify(request),
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (data) {
|
success: function (result) {
|
||||||
if (!data.succ) {
|
if (!result.succ) {
|
||||||
$("#dialogRemoveConfirm").dialog("close");
|
$("#dialogRemoveConfirm").dialog("close");
|
||||||
bottomGroup.tabs.setCurrent("notification");
|
bottomGroup.tabs.setCurrent("notification");
|
||||||
windows.flowBottom();
|
windows.flowBottom();
|
||||||
|
@ -155,8 +155,8 @@ var wide = {
|
||||||
url: config.context + '/file/new',
|
url: config.context + '/file/new',
|
||||||
data: JSON.stringify(request),
|
data: JSON.stringify(request),
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (data) {
|
success: function (result) {
|
||||||
if (!data.succ) {
|
if (!result.succ) {
|
||||||
$("#dialogNewFilePrompt").dialog("close");
|
$("#dialogNewFilePrompt").dialog("close");
|
||||||
bottomGroup.tabs.setCurrent("notification");
|
bottomGroup.tabs.setCurrent("notification");
|
||||||
windows.flowBottom();
|
windows.flowBottom();
|
||||||
|
@ -199,8 +199,8 @@ var wide = {
|
||||||
url: config.context + '/file/new',
|
url: config.context + '/file/new',
|
||||||
data: JSON.stringify(request),
|
data: JSON.stringify(request),
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (data) {
|
success: function (result) {
|
||||||
if (!data.succ) {
|
if (!result.succ) {
|
||||||
$("#dialogNewDirPrompt").dialog("close");
|
$("#dialogNewDirPrompt").dialog("close");
|
||||||
bottomGroup.tabs.setCurrent("notification");
|
bottomGroup.tabs.setCurrent("notification");
|
||||||
windows.flowBottom();
|
windows.flowBottom();
|
||||||
|
@ -356,8 +356,7 @@ var wide = {
|
||||||
url: config.context + '/git/clone',
|
url: config.context + '/git/clone',
|
||||||
data: JSON.stringify(request),
|
data: JSON.stringify(request),
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (data) {
|
success: function (result) {
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -672,9 +671,9 @@ var wide = {
|
||||||
url: config.context + '/go/fmt',
|
url: config.context + '/go/fmt',
|
||||||
data: JSON.stringify(request),
|
data: JSON.stringify(request),
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (data) {
|
success: function (result) {
|
||||||
if (data.succ) {
|
if (result.succ) {
|
||||||
editor.setValue(data.code);
|
editor.setValue(result.data.code);
|
||||||
editor.setCursor(cursor);
|
editor.setCursor(cursor);
|
||||||
editor.scrollTo(null, scrollInfo.top);
|
editor.scrollTo(null, scrollInfo.top);
|
||||||
|
|
||||||
|
@ -705,9 +704,9 @@ var wide = {
|
||||||
url: config.context + '/go/fmt',
|
url: config.context + '/go/fmt',
|
||||||
data: JSON.stringify(request),
|
data: JSON.stringify(request),
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (data) {
|
success: function (result) {
|
||||||
if (data.succ) {
|
if (result.succ) {
|
||||||
formatted = data.code;
|
formatted = result.data.code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -81,8 +81,8 @@
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
success: function (data) {
|
success: function (result) {
|
||||||
if (!data.succ) {
|
if (!result.succ) {
|
||||||
$("#msg").text('{{.i18n.login_error}}').show();
|
$("#msg").text('{{.i18n.login_error}}').show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,9 +96,9 @@
|
||||||
url: '/signup',
|
url: '/signup',
|
||||||
data: JSON.stringify(request),
|
data: JSON.stringify(request),
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (data) {
|
success: function (result) {
|
||||||
if (!data.succ) {
|
if (!result.succ) {
|
||||||
$("#msg").text(data.msg).show();
|
$("#msg").text(result.msg).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue