可以使用Visual Studio Code调试Go Revel框架吗?

huangapple go评论94阅读模式
英文:

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 -->

{
  &quot;version&quot;: &quot;0.2.0&quot;,
  &quot;configurations&quot;: [
    {
      &quot;name&quot;: &quot;Launch&quot;,
      &quot;type&quot;: &quot;go&quot;,
      &quot;request&quot;: &quot;launch&quot;,
      &quot;mode&quot;: &quot;debug&quot;,
      &quot;remotePath&quot;: &quot;&quot;,
      &quot;port&quot;: 2345,
      &quot;host&quot;: &quot;127.0.0.1&quot;,
      &quot;program&quot;: &quot;~/code/go/bin/revel&quot;,
      &quot;env&quot;: {},
      &quot;args&quot;: [],
      &quot;showLog&quot;: true
    }
  ]
}

<!-- end snippet -->

But I'm getting this error:
Failed to continue: &quot;The program attribute must point to valid directory, .go file or executable.&quot;

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

是的,这是可能的。

  1. 假设GOPATHC:\Work\golang

  2. Revel项目名称为myapp,因此项目(工作区)的位置将是C:\Work\golang\src\myapp

  3. 对控制器等进行一些更改...

  4. 使用revel run myapp运行应用程序,然后按下CTRL+C退出。这一步是为了生成相应的go文件。生成的文件,即main包,将在${workspaceRoot}/app/tmp/main.go下可用。

  5. 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"]
             }
         ]
     }
    
  6. programargs参数是重要的部分,而其他参数保持不变。

  7. 设置breakpoint并启动delve调试器...

编辑:##

  1. args参数设置为["-importPath", "myapp", "-srcPath", "${workspaceRoot}/..", "-runMode", "dev"]也可以工作,我认为这在其他平台(Mac、Linux)上也可以工作。
  2. 错误消息与delve问题有关。请参阅https://github.com/Microsoft/vscode-go/issues/986

可以使用Visual Studio Code调试Go Revel框架吗?

英文:

Yes it's possible.

  1. Suppose that the GOPATH is C:\Work\golang

  2. Revel project name is myapp, thus the location of the project (workspace) will be C:\Work\golang\src\myapp.

  3. Make some changes to the controllers etc...

  4. Run the application with revel run myapp, then press CTRL+C to exit. This step is necessary to generate corresponding go files. The generated file, i.e. the main package will be available under ${workspaceRoot}/app/tmp/main.go

  5. Configure launch.json as follows:

    {
        &quot;version&quot;: &quot;0.2.0&quot;,
        &quot;configurations&quot;: [
            {
                &quot;name&quot;: &quot;Launch&quot;,
                &quot;type&quot;: &quot;go&quot;,
                &quot;request&quot;: &quot;launch&quot;,
                &quot;mode&quot;: &quot;debug&quot;,
                &quot;remotePath&quot;: &quot;&quot;,
                &quot;port&quot;: 2345,
                &quot;host&quot;: &quot;127.0.0.1&quot;,
                &quot;env&quot;: {},
                &quot;showLog&quot;: true,
                &quot;program&quot;: &quot;${workspaceRoot}/app/tmp/&quot;,
                &quot;args&quot;: [&quot;-importPath&quot;, &quot;myapp&quot;, &quot;-srcPath&quot;, &quot;c:\\work\\golang\\src&quot;,  &quot;-runMode&quot;, &quot;dev&quot;]
            }
        ]
    }
    
  6. The important parts are program and args parameters, while the other parameters are unmodified.

  7. Set breakpoint and start the delve debugger...

可以使用Visual Studio Code调试Go Revel框架吗?

EDIT:

  1. Setting args parameter to [&quot;-importPath&quot;, &quot;myapp&quot;, &quot;-srcPath&quot;, &quot;${workspaceRoot}/..&quot;, &quot;-runMode&quot;, &quot;dev&quot;] also work, and I think this should work in other platforms (Mac, Linux) too.
  2. The error message is related to delve issue. See https://github.com/Microsoft/vscode-go/issues/986

huangapple
  • 本文由 发表于 2017年6月16日 20:58:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/44589854.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定