This commit is contained in:
Liang Ding 2019-05-16 18:10:44 +08:00
parent e97ce75b92
commit 7deb7c60e5
No known key found for this signature in database
GPG Key ID: 136F30F901A2231D
4 changed files with 32 additions and 15 deletions

View File

@ -174,7 +174,7 @@ func main() {
http.HandleFunc(conf.Wide.Context+"/playground/save", handlerWrapper(playground.SaveHandler)) http.HandleFunc(conf.Wide.Context+"/playground/save", handlerWrapper(playground.SaveHandler))
http.HandleFunc(conf.Wide.Context+"/playground/short-url", handlerWrapper(playground.ShortURLHandler)) http.HandleFunc(conf.Wide.Context+"/playground/short-url", handlerWrapper(playground.ShortURLHandler))
http.HandleFunc(conf.Wide.Context+"/playground/build", handlerWrapper(playground.BuildHandler)) http.HandleFunc(conf.Wide.Context+"/playground/build", handlerWrapper(playground.BuildHandler))
http.HandleFunc(conf.Wide.Context+"/playground/run", handlerWrapper(playground.RunHandler)) http.HandleFunc(conf.Wide.Context+"/playground/run", handlerWrapper(output.RunHandler))
http.HandleFunc(conf.Wide.Context+"/playground/stop", handlerWrapper(playground.StopHandler)) http.HandleFunc(conf.Wide.Context+"/playground/stop", handlerWrapper(playground.StopHandler))
http.HandleFunc(conf.Wide.Context+"/playground/autocomplete", handlerWrapper(playground.AutocompleteHandler)) http.HandleFunc(conf.Wide.Context+"/playground/autocomplete", handlerWrapper(playground.AutocompleteHandler))

View File

@ -188,6 +188,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
err = wsChannel.WriteJSON(&channelRet) err = wsChannel.WriteJSON(&channelRet)
if nil != err { if nil != err {
logger.Warn(err) logger.Warn(err)
break break
} }

View File

@ -111,13 +111,17 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
go func() { go func() {
defer util.Recover() defer util.Recover()
outScanner := bufio.NewScanner(outReader) for {
for outScanner.Scan() { r, _, err := outReader.ReadRune()
oneRuneStr := outScanner.Text() if nil != err {
break
}
oneRuneStr := string(r)
oneRuneStr = strings.Replace(oneRuneStr, "<", "&lt;", -1) oneRuneStr = strings.Replace(oneRuneStr, "<", "&lt;", -1)
oneRuneStr = strings.Replace(oneRuneStr, ">", "&gt;", -1) oneRuneStr = strings.Replace(oneRuneStr, ">", "&gt;", -1)
channelRet["cmd"] = "run" channelRet["cmd"] = "run"
channelRet["output"] = oneRuneStr + "\n" channelRet["output"] = oneRuneStr
wsChannel := session.OutputWS[sid] wsChannel := session.OutputWS[sid]
if nil != wsChannel { if nil != wsChannel {
wsChannel.WriteJSON(&channelRet) wsChannel.WriteJSON(&channelRet)
@ -126,9 +130,13 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
} }
}() }()
errScanner := bufio.NewScanner(errReader) for {
for errScanner.Scan() { r, _, err := errReader.ReadRune()
oneRuneStr := errScanner.Text() if nil != err {
break
}
oneRuneStr := string(r)
oneRuneStr = strings.Replace(oneRuneStr, "<", "&lt;", -1) oneRuneStr = strings.Replace(oneRuneStr, "<", "&lt;", -1)
oneRuneStr = strings.Replace(oneRuneStr, ">", "&gt;", -1) oneRuneStr = strings.Replace(oneRuneStr, ">", "&gt;", -1)
channelRet["cmd"] = "run" channelRet["cmd"] = "run"

View File

@ -123,13 +123,17 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
go func() { go func() {
defer util.Recover() defer util.Recover()
outScanner := bufio.NewScanner(outReader) for {
for outScanner.Scan() { r, _, err := outReader.ReadRune()
oneRuneStr := outScanner.Text() if nil != err {
break
}
oneRuneStr := string(r)
oneRuneStr = strings.Replace(oneRuneStr, "<", "&lt;", -1) oneRuneStr = strings.Replace(oneRuneStr, "<", "&lt;", -1)
oneRuneStr = strings.Replace(oneRuneStr, ">", "&gt;", -1) oneRuneStr = strings.Replace(oneRuneStr, ">", "&gt;", -1)
channelRet["cmd"] = "run" channelRet["cmd"] = "run"
channelRet["output"] = oneRuneStr + "\n" channelRet["output"] = oneRuneStr
wsChannel := session.OutputWS[sid] wsChannel := session.OutputWS[sid]
if nil != wsChannel { if nil != wsChannel {
wsChannel.WriteJSON(&channelRet) wsChannel.WriteJSON(&channelRet)
@ -138,9 +142,13 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
} }
}() }()
errScanner := bufio.NewScanner(errReader) for {
for errScanner.Scan() { r, _, err := errReader.ReadRune()
oneRuneStr := errScanner.Text() if nil != err {
break
}
oneRuneStr := string(r)
oneRuneStr = strings.Replace(oneRuneStr, "<", "&lt;", -1) oneRuneStr = strings.Replace(oneRuneStr, "<", "&lt;", -1)
oneRuneStr = strings.Replace(oneRuneStr, ">", "&gt;", -1) oneRuneStr = strings.Replace(oneRuneStr, ">", "&gt;", -1)
channelRet["cmd"] = "run" channelRet["cmd"] = "run"