dongren4147
2017-06-16 12:58
浏览 459
已采纳

是否可以从Visual Studio Code调试go revel框架?

I'm trying to debug a revel app with visual studio but I can't get it to work.

I've seen this question how to debug revel framework(golang) application in visual studio code(vscode) but no answers yet...

I've tried with this config:

{
  "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
    }
  ]
}

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

</div>

图片转代码服务由CSDN问答提供 功能建议

我正在尝试使用Visual Studio调试Revel应用,但无法正常工作。

我已经看到了这个问题如何在Visual Studio代码(vscode)中调试revel framework(golang)应用程序,但目前还没有答案...

我已经尝试过使用此配置:< / p>

  {
 
“ version”:“ 0.2  .0“,
 
”配置“:[
 
 {
 
”名称“:”启动“,
 
”类型“:” go“,
 
”请求“:  “启动”,
 
“模式”:“调试”,
 
“ remotePath”:“”,
 
“端口”:2345,
 
“主机”:“ 127.0.0.1”  ,
 
“ program”:“〜/ code / go / bin / revel”,
 
“ env”:{},
 
“ args”:[],
 
“ showLog”  :tr  ue 
 
} 
 
] 
 
}   
 
  
 
  
 
 
 
 

但我遇到此错误: 无法继续:“程序属性必须指向有效目录,.go文件或可执行文件。”

我认为它必须是在这里运行的rebel二进制文件,但是我不知道如何传递应用程序路径,它应该放在“ args”中吗?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongnao2048 2017-06-16 16:56
    已采纳

    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:

      {
          "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. The important parts are program and args parameters, while the other parameters are unmodified.

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

    Debug revel application

    EDIT:

    1. Setting args parameter to ["-importPath", "myapp", "-srcPath", "${workspaceRoot}/..", "-runMode", "dev"] 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
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题