This commit is contained in:
Liang Ding 2014-10-23 16:05:21 +08:00
parent db36400f57
commit 2f6b9f0e2f
1 changed files with 19 additions and 55 deletions

View File

@ -495,7 +495,6 @@ func GoInstallHandler(w http.ResponseWriter, r *http.Request) {
glog.V(3).Infof("Session [%s] is running [go install] [id=%d, dir=%s]", sid, runningId, curDir) glog.V(3).Infof("Session [%s] is running [go install] [id=%d, dir=%s]", sid, runningId, curDir)
// 一次性读取
// 一次性读取 // 一次性读取
buf, _ := ioutil.ReadAll(reader) buf, _ := ioutil.ReadAll(reader)
@ -654,51 +653,18 @@ func GoGetHandler(w http.ResponseWriter, r *http.Request) {
channelRet := map[string]interface{}{} channelRet := map[string]interface{}{}
channelRet["cmd"] = "go get" channelRet["cmd"] = "go get"
for { // 一次性读取
buf, err := reader.ReadBytes('\n') buf, _ := ioutil.ReadAll(reader)
channelRet["output"] = string(buf) if 0 != len(buf) {
glog.V(3).Infof("Session [%s] 's running [go get] [runningId=%d] has done (with error)", sid, runningId)
if nil != err {
glog.V(3).Infof("Session [%s] 's running [go get] [runningId=%d] has done (with error: %v)", sid, runningId, err)
channelRet["output"] = "<span class='get-failed'>" + i18n.Get(r, "get-failed").(string) + "</span>\n" + string(buf) channelRet["output"] = "<span class='get-failed'>" + i18n.Get(r, "get-failed").(string) + "</span>\n" + string(buf)
} else {
if nil != session.OutputWS[sid] {
wsChannel := session.OutputWS[sid]
err := wsChannel.Conn.WriteJSON(&channelRet)
if nil != err {
glog.Error(err)
break
}
// 更新通道最近使用时间
wsChannel.Time = time.Now()
}
break
}
if 0 == len(buf) {
glog.V(3).Infof("Session [%s] 's running [go get] [runningId=%d] has done", sid, runningId) glog.V(3).Infof("Session [%s] 's running [go get] [runningId=%d] has done", sid, runningId)
channelRet["output"] = "<span class='get-succ'>" + i18n.Get(r, "get-succ").(string) + "</span>\n" channelRet["output"] = "<span class='get-succ'>" + i18n.Get(r, "get-succ").(string) + "</span>\n"
if nil != session.OutputWS[sid] {
wsChannel := session.OutputWS[sid]
err := wsChannel.Conn.WriteJSON(&channelRet)
if nil != err {
glog.Error(err)
break
}
// 更新通道最近使用时间
wsChannel.Time = time.Now()
}
break
} }
if nil != session.OutputWS[sid] { if nil != session.OutputWS[sid] {
@ -707,13 +673,11 @@ func GoGetHandler(w http.ResponseWriter, r *http.Request) {
err := wsChannel.Conn.WriteJSON(&channelRet) err := wsChannel.Conn.WriteJSON(&channelRet)
if nil != err { if nil != err {
glog.Error(err) glog.Error(err)
break
} }
// 更新通道最近使用时间 // 更新通道最近使用时间
wsChannel.Time = time.Now() wsChannel.Time = time.Now()
} }
}
}(rand.Int()) }(rand.Int())
} }