1. First install GO
Go download address: go.dev
Select the corresponding version, download, run the installer, open a command prompt, run go env, and confirm that go has been installed
Pay attention to GOPATH and GOROOT, these two addresses can be set in the system environment variables.
Find "Edit System Environment Variables" in "Settings", then click "Advanced", click "Environment Variables", and add two variables "GOPATH" and "GOROOT".
Then add GOPATH and GOROOT to the "Path" variable, as follows:
After the configuration is complete, enter go env to check whether the setting is successful.
2. Install Visual Studio Code
Download address: Visual Studio Code - Code Editing. Redefined
After the installation is complete, open the extension and install the three extensions of Chinese, code runner, and Go respectively
3. Continue to configure the Go extension
Open the extension settings of the GO extension
Find Gopath in it, click to edit in settings.json
Just write the GOPATH and GOROOT you set
4. Debugging
Generally speaking, it can be debugged directly. The code opens the main page, that is, the code page where the main function is located. Press F5 (Fn+F5) to enter the debug page.
At this point you can break the point for debugging.
What if you want to enter parameters for debugging?
You can create a new .vscode folder in the root directory of the project, and create a launch.json file in the folder, which is the file launched during debugging. Generally speaking, it will be created automatically, you only need to write the required parameters in the args keyword.
reference:
Configure Visual Studio Code for Go development - Go on Azure | Microsoft Learn