Here is how I used VSCODE to debug Go in Windows 10

Click on VSCODE’s “run and debug” feature, and a launch.json file appears. Fill this file with the configuration information needed for debugging. Here is a more detailed example. For reference only.

{
    // Use IntelliSense to learn about related attributes.
    // Hover to view descriptions of existing properties.
    / / for more information, please visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0"."configurations": [{"name": "launch game"."type": "go"."request": "launch"."mode": "auto"."program": "${fileDirname}/.. /game/main.go"."cwd": "${fileDirname}/.. /"."args": [
                "--dburl"."127.0.0.1:27017"."--mqurl"."Nats: / / 127.0.0.1:4222"."--pfenv"."dev"."--servername"."b3"."--etcdcenter"."127.0.0.1:2379"."--serverid"."406"."--project"."b3d1"."--csv"."b3d1"."--loglevel"."debug"] {},"name": "launch gate"."type": "go"."request": "launch"."mode": "auto"."program": "${fileDirname}/.. /gate/main.go"."cwd": "${fileDirname}/.. /"."args": [
                "--doordburl"."0.0.0.0:27017"."--project"."b3d1"."--pfenv"."dev"."--etcdcenter"."127.0.0.1:2379"."--serverid"."406"."--loglevel"."debug"] {},"name": "launch gswatcher"."type": "go"."request": "launch"."mode": "auto"."program": "${fileDirname}/.. /client/gswatcher/main.go"."cwd": "${fileDirname}/.. /"."args": [
                "--gateaddr"."127.0.0.1:21406"."--project"."b3d1"."--dburl"."127.0.0.1:27017"]},]}Copy the code

Description of document contents:

  • ${fileDirname} indicates the location of the launch.json file, usually in the.vscode folder in the current project folder.
  • The Program configuration item specifies the Go file to execute
  • The CWD configuration item specifies the working path after the process is started
  • The args configuration item specifies the command line parameters for starting a process. It’s an array of strings. Notice how the parameters are listed.
  • Configurations configures multiple objects so that multiple processes can be launched in succession.