This commit is contained in:
parent
12b8f780d9
commit
73cd1c6538
|
@ -5,5 +5,5 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hello, 世界")
|
||||
fmt.Println("Hello, 世界")1
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
cmd.Start()
|
||||
|
||||
rec := map[string]interface{}{}
|
||||
channelRet := map[string]interface{}{}
|
||||
|
||||
go func(runningId int) {
|
||||
glog.Infof("Session [%s] is running [id=%d, file=%s]", sid, runningId, filePath)
|
||||
|
@ -83,10 +83,11 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
break
|
||||
} else {
|
||||
rec["output"] = string(buf[:count])
|
||||
channelRet["output"] = string(buf[:count])
|
||||
channelRet["cmd"] = "run"
|
||||
|
||||
if nil != outputWS[sid] {
|
||||
err := outputWS[sid].WriteJSON(&rec)
|
||||
err := outputWS[sid].WriteJSON(&channelRet)
|
||||
if nil != err {
|
||||
glog.Error(err)
|
||||
break
|
||||
|
@ -150,7 +151,12 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
|||
cmd := exec.Command("go", argv...)
|
||||
cmd.Dir = curDir
|
||||
|
||||
glog.Info("go build ", filePath)
|
||||
glog.Infof("go build -o %s %s", executable, filePath)
|
||||
|
||||
executable = curDir + string(os.PathSeparator) + executable
|
||||
|
||||
// 先把可执行文件删了
|
||||
os.RemoveAll(executable)
|
||||
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if nil != err {
|
||||
|
@ -184,7 +190,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
|||
channelRet["output"] = string(buf[:count])
|
||||
channelRet["cmd"] = "build"
|
||||
channelRet["nextCmd"] = "run"
|
||||
channelRet["executable"] = curDir + string(os.PathSeparator) + executable
|
||||
channelRet["executable"] = executable
|
||||
|
||||
if nil != outputWS[sid] {
|
||||
glog.Infof("Session [%s] 's build [id=%d, file=%s] has done", sid, runningId, filePath)
|
||||
|
|
|
@ -2,12 +2,23 @@ var outputWS = new WebSocket(config.channel.output + '/output/ws');
|
|||
outputWS.onopen = function() {
|
||||
console.log('[output onopen] connected');
|
||||
};
|
||||
|
||||
outputWS.onmessage = function(e) {
|
||||
console.log('[output onmessage]' + e.data);
|
||||
var data = JSON.parse(e.data);
|
||||
|
||||
if ('init-output' !== data.cmd) {
|
||||
if ('run' === data.cmd) {
|
||||
console.log('run: ' + data.cmd);
|
||||
|
||||
$('#output').val($('#output').val() + data.output);
|
||||
} else if ('build' === data.cmd) {
|
||||
console.log('build: ' + data.cmd);
|
||||
|
||||
$('#output').val(data.output);
|
||||
|
||||
if (0 != data.output.length) { // 说明编译有错误输出
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ('build' == data.cmd) {
|
||||
|
@ -22,9 +33,10 @@ outputWS.onmessage = function(e) {
|
|||
data: JSON.stringify(request),
|
||||
dataType: "json",
|
||||
beforeSend: function(data) {
|
||||
$('#output').val('');
|
||||
$('#output').val('');
|
||||
},
|
||||
success: function(data) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue