✨ #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)
|
filePath := args["file"].(string)
|
||||||
curDir := filepath.Dir(filePath)
|
curDir := filepath.Dir(filePath)
|
||||||
|
curDirName := filepath.Base(curDir)
|
||||||
|
|
||||||
cmd := exec.Command("go", "mod")
|
cmd := exec.Command("go", "mod", "init", curDirName)
|
||||||
cmd.Dir = curDir
|
cmd.Dir = curDir
|
||||||
|
|
||||||
setCmdEnv(cmd, uid)
|
setCmdEnv(cmd, uid)
|
||||||
|
@ -110,37 +111,26 @@ func GoModHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
go func(runningId int) {
|
runningId := rand.Int()
|
||||||
defer util.Recover()
|
|
||||||
defer cmd.Wait()
|
|
||||||
|
|
||||||
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 := map[string]interface{}{}
|
|
||||||
channelRet["cmd"] = "go mod"
|
channelRet["cmd"] = "go mod"
|
||||||
|
|
||||||
// read all
|
|
||||||
buf, _ := ioutil.ReadAll(reader)
|
buf, _ := ioutil.ReadAll(reader)
|
||||||
|
output := string(buf)
|
||||||
if 0 != len(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)
|
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
|
||||||
channelRet["output"] = "<span class='mod-error'>" + i18n.Get(locale, "mod-error").(string) + "</span>\n" + string(buf)
|
|
||||||
} else {
|
} else {
|
||||||
logger.Debugf("User [%s, %s] 's running [go mod] [runningId=%d] has done", uid, sid, runningId)
|
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
|
||||||
channelRet["output"] = "<span class='mod-succ'>" + i18n.Get(locale, "mod-succ").(string) + "</span>\n"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if nil != session.OutputWS[sid] {
|
|
||||||
wsChannel := session.OutputWS[sid]
|
wsChannel := session.OutputWS[sid]
|
||||||
|
if nil != wsChannel {
|
||||||
err := wsChannel.WriteJSON(&channelRet)
|
wsChannel.WriteJSON(&channelRet)
|
||||||
if nil != err {
|
|
||||||
logger.Warn(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
wsChannel.Refresh()
|
wsChannel.Refresh()
|
||||||
}
|
}
|
||||||
}(rand.Int())
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,7 +178,7 @@ var editors = {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (editors.data.length === 0) { // 起始页可能存在,所以用编辑器数据判断
|
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',
|
'find', 'find-next', 'find-previous', 'replace', 'replace-all',
|
||||||
'format', 'autocomplete', 'jump-to-decl', 'expr-info', 'find-usages', 'toggle-comment',
|
'format', 'autocomplete', 'jump-to-decl', 'expr-info', 'find-usages', 'toggle-comment',
|
||||||
'edit']);
|
'edit']);
|
||||||
|
@ -732,7 +732,7 @@ var editors = {
|
||||||
content: '<textarea id="editor' + id + '"></textarea>'
|
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',
|
'find', 'find-next', 'find-previous', 'replace', 'replace-all',
|
||||||
'format', 'autocomplete', 'jump-to-decl', 'expr-info', 'find-usages', 'toggle-comment',
|
'format', 'autocomplete', 'jump-to-decl', 'expr-info', 'find-usages', 'toggle-comment',
|
||||||
'edit']);
|
'edit']);
|
||||||
|
|
|
@ -180,7 +180,7 @@ var menu = {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($(".menu li.go-get").hasClass("disabled")) {
|
if ($(".menu li.go-mod").hasClass("disabled")) {
|
||||||
return false;
|
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