✨ #306 支持 go mod
This commit is contained in:
parent
00051a9e39
commit
d3f522acd9
|
@ -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)
|
||||
|
||||
channelRet := map[string]interface{}{}
|
||||
channelRet = map[string]interface{}{}
|
||||
channelRet["cmd"] = "go mod"
|
||||
|
||||
// read all
|
||||
buf, _ := ioutil.ReadAll(reader)
|
||||
|
||||
if 0 != len(buf) {
|
||||
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" + string(buf)
|
||||
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"
|
||||
channelRet["output"] = "<span class='mod-succ'>" + i18n.Get(locale, "mod-succ").(string) + "</span>\n" + output
|
||||
}
|
||||
|
||||
if nil != session.OutputWS[sid] {
|
||||
wsChannel := session.OutputWS[sid]
|
||||
|
||||
err := wsChannel.WriteJSON(&channelRet)
|
||||
if nil != err {
|
||||
logger.Warn(err)
|
||||
}
|
||||
|
||||
if nil != wsChannel {
|
||||
wsChannel.WriteJSON(&channelRet)
|
||||
wsChannel.Refresh()
|
||||
}
|
||||
}(rand.Int())
|
||||
}
|
||||
|
|
|
@ -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']);
|
||||
|
|
|
@ -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
Loading…
Reference in New Issue