英文:
Is it possible to debug go revel framework from Visual Studio Code?
问题
我正在尝试使用Visual Studio调试Revel应用程序,但无法使其工作。
我看到了这个问题https://stackoverflow.com/questions/41171432/how-to-debug-revel-frameworkgolang-application-in-visual-studio-codevscode,但还没有答案...
我尝试了这个配置:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "~/code/go/bin/revel",
"env": {},
"args": [],
"showLog": true
}
]
}
但是我得到了这个错误:
Failed to continue: "The program attribute must point to valid directory, .go file or executable."
我认为在这里应该运行revel二进制文件,但我不知道如何传递应用程序路径,它应该放在"args"中吗?
英文:
I'm trying to debug a revel app with visual studio but I can't get it to work.
I've seen this question https://stackoverflow.com/questions/41171432/how-to-debug-revel-frameworkgolang-application-in-visual-studio-codevscode but no answers yet...
I've tried with this config:
<!-- begin snippet: js hide: false console: false babel: false -->
<!-- language: lang-html -->
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "~/code/go/bin/revel",
"env": {},
"args": [],
"showLog": true
}
]
}
<!-- end snippet -->
But I'm getting this error:
Failed to continue: "The program attribute must point to valid directory, .go file or executable."
I think it must be the rebel binary the one to be run here, but I don't know how to pass the app path, should it go in "args"?
答案1
得分: 7
是的,这是可能的。
-
假设
GOPATH是C:\Work\golang。 -
Revel项目名称为
myapp,因此项目(工作区)的位置将是C:\Work\golang\src\myapp。 -
对控制器等进行一些更改...
-
使用
revel run myapp运行应用程序,然后按下CTRL+C退出。这一步是为了生成相应的go文件。生成的文件,即main包,将在${workspaceRoot}/app/tmp/main.go下可用。 -
将
launch.json配置如下:{ "version": "0.2.0", "configurations": [ { "name": "Launch", "type": "go", "request": "launch", "mode": "debug", "remotePath": "", "port": 2345, "host": "127.0.0.1", "env": {}, "showLog": true, "program": "${workspaceRoot}/app/tmp/", "args": ["-importPath", "myapp", "-srcPath", "c:\\work\\golang\\src", "-runMode", "dev"] } ] } -
program和args参数是重要的部分,而其他参数保持不变。 -
设置
breakpoint并启动delve调试器...
编辑:##
- 将
args参数设置为["-importPath", "myapp", "-srcPath", "${workspaceRoot}/..", "-runMode", "dev"]也可以工作,我认为这在其他平台(Mac、Linux)上也可以工作。 - 错误消息与
delve问题有关。请参阅https://github.com/Microsoft/vscode-go/issues/986
英文:
Yes it's possible.
-
Suppose that the
GOPATHisC:\Work\golang -
Revel project name is
myapp, thus the location of the project (workspace) will beC:\Work\golang\src\myapp. -
Make some changes to the controllers etc...
-
Run the application with
revel run myapp, then pressCTRL+Cto exit. This step is necessary to generate corresponding go files. The generated file, i.e. themainpackage will be available under${workspaceRoot}/app/tmp/main.go -
Configure
launch.jsonas follows:{ "version": "0.2.0", "configurations": [ { "name": "Launch", "type": "go", "request": "launch", "mode": "debug", "remotePath": "", "port": 2345, "host": "127.0.0.1", "env": {}, "showLog": true, "program": "${workspaceRoot}/app/tmp/", "args": ["-importPath", "myapp", "-srcPath", "c:\\work\\golang\\src", "-runMode", "dev"] } ] } -
The important parts are
programandargsparameters, while the other parameters are unmodified. -
Set
breakpointand start thedelvedebugger...
EDIT:
- Setting
argsparameter to["-importPath", "myapp", "-srcPath", "${workspaceRoot}/..", "-runMode", "dev"]also work, and I think this should work in other platforms (Mac, Linux) too. - The error message is related to
delveissue. See https://github.com/Microsoft/vscode-go/issues/986
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。



评论