From 2f6b9f0e2f62ffca61da3a5e688d1de9bcdd1988 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 23 Oct 2014 16:05:21 +0800 Subject: [PATCH] . --- output/outputs.go | 74 ++++++++++++----------------------------------- 1 file changed, 19 insertions(+), 55 deletions(-) diff --git a/output/outputs.go b/output/outputs.go index 0a72b83..a260814 100644 --- a/output/outputs.go +++ b/output/outputs.go @@ -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) - // 一次性读取 // 一次性读取 buf, _ := ioutil.ReadAll(reader) @@ -654,65 +653,30 @@ func GoGetHandler(w http.ResponseWriter, r *http.Request) { channelRet := map[string]interface{}{} 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) + channelRet["output"] = "" + i18n.Get(r, "get-failed").(string) + "\n" + string(buf) + } else { + glog.V(3).Infof("Session [%s] 's running [go get] [runningId=%d] has done", sid, runningId) + + channelRet["output"] = "" + i18n.Get(r, "get-succ").(string) + "\n" + + } + + if nil != session.OutputWS[sid] { + wsChannel := session.OutputWS[sid] + + err := wsChannel.Conn.WriteJSON(&channelRet) 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"] = "" + i18n.Get(r, "get-failed").(string) + "\n" + string(buf) - - 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 + glog.Error(err) } - if 0 == len(buf) { - glog.V(3).Infof("Session [%s] 's running [go get] [runningId=%d] has done", sid, runningId) - - channelRet["output"] = "" + i18n.Get(r, "get-succ").(string) + "\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] { - wsChannel := session.OutputWS[sid] - - err := wsChannel.Conn.WriteJSON(&channelRet) - if nil != err { - glog.Error(err) - break - } - - // 更新通道最近使用时间 - wsChannel.Time = time.Now() - } + // 更新通道最近使用时间 + wsChannel.Time = time.Now() } }(rand.Int()) }