#306 支持 go mod

This commit is contained in:
Liang Ding 2019-05-20 17:36:16 +08:00
parent 00051a9e39
commit d3f522acd9
No known key found for this signature in database
GPG Key ID: 136F30F901A2231D
5 changed files with 27 additions and 37 deletions

View File

@ -56,8 +56,9 @@ func GoModHandler(w http.ResponseWriter, r *http.Request) {
filePath := args["file"].(string)
curDir := filepath.Dir(filePath)
curDirName := filepath.Base(curDir)
cmd := exec.Command("go", "mod")
cmd := exec.Command("go", "mod", "init", curDirName)
cmd.Dir = curDir
setCmdEnv(cmd, uid)
@ -110,37 +111,26 @@ func GoModHandler(w http.ResponseWriter, r *http.Request) {
return
}
go func(runningId int) {
defer util.Recover()
defer cmd.Wait()
runningId := rand.Int()
logger.Debugf("User [%s, %s] is running [go mod] [runningId=%d]", uid, sid, runningId)
logger.Debugf("User [%s, %s] is running [go mod] [runningId=%d]", uid, sid, runningId)
channelRet = map[string]interface{}{}
channelRet["cmd"] = "go mod"
channelRet := map[string]interface{}{}
channelRet["cmd"] = "go mod"
buf, _ := ioutil.ReadAll(reader)
output := string(buf)
err = cmd.Wait()
if nil != err || 0 != cmd.ProcessState.ExitCode() {
logger.Debugf("User [%s, %s] 's [go mod] [runningId=%d] has done (with error)", uid, sid, runningId)
channelRet["output"] = "<span class='mod-error'>" + i18n.Get(locale, "mod-error").(string) + "</span>\n" + output
} else {
logger.Debugf("User [%s, %s] 's running [go mod] [runningId=%d] has done", uid, sid, runningId)
channelRet["output"] = "<span class='mod-succ'>" + i18n.Get(locale, "mod-succ").(string) + "</span>\n" + output
}
// read all
buf, _ := ioutil.ReadAll(reader)
if 0 != len(buf) {
logger.Debugf("User [%s, %s] 's [go mod] [runningId=%d] has done (with error)", uid, sid, runningId)
channelRet["output"] = "<span class='mod-error'>" + i18n.Get(locale, "mod-error").(string) + "</span>\n" + string(buf)
} else {
logger.Debugf("User [%s, %s] 's running [go mod] [runningId=%d] has done", uid, sid, runningId)
channelRet["output"] = "<span class='mod-succ'>" + i18n.Get(locale, "mod-succ").(string) + "</span>\n"
}
if nil != session.OutputWS[sid] {
wsChannel := session.OutputWS[sid]
err := wsChannel.WriteJSON(&channelRet)
if nil != err {
logger.Warn(err)
}
wsChannel.Refresh()
}
}(rand.Int())
wsChannel := session.OutputWS[sid]
if nil != wsChannel {
wsChannel.WriteJSON(&channelRet)
wsChannel.Refresh()
}
}

View File

@ -178,7 +178,7 @@ var editors = {
}
if (editors.data.length === 0) { // 起始页可能存在,所以用编辑器数据判断
menu.disabled(['save-all', 'build', 'run', 'go-test', 'go-vet', 'go-get', 'go-install',
menu.disabled(['save-all', 'build', 'run', 'go-test', 'go-vet', 'go-mod', 'go-install',
'find', 'find-next', 'find-previous', 'replace', 'replace-all',
'format', 'autocomplete', 'jump-to-decl', 'expr-info', 'find-usages', 'toggle-comment',
'edit']);
@ -732,7 +732,7 @@ var editors = {
content: '<textarea id="editor' + id + '"></textarea>'
});
menu.undisabled(['save-all', 'close-all', 'build', 'run', 'go-test', 'go-vet', 'go-get', 'go-install',
menu.undisabled(['save-all', 'close-all', 'build', 'run', 'go-test', 'go-vet', 'go-mod', 'go-install',
'find', 'find-next', 'find-previous', 'replace', 'replace-all',
'format', 'autocomplete', 'jump-to-decl', 'expr-info', 'find-usages', 'toggle-comment',
'edit']);

View File

@ -180,7 +180,7 @@ var menu = {
return false;
}
if ($(".menu li.go-get").hasClass("disabled")) {
if ($(".menu li.go-mod").hasClass("disabled")) {
return false;
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long