Debug Golang with VSCode
Example
Create a simple go lang file with the below code:
- main.go
1 | package main |
Make sure the go.mod is initialized
- go.mod
1 | module test-debug |
it will print the args from the command-line args
Switch to the Run and Debug
And choose the create a launch.json
file and fill in the config for debugging
The config example is below:
1 | { |
the args are the arguments you want to put after the go program, for example:
go run main.go nick ben
then the “args“ is:
"args": ["nick","ben"]