Install and Configure Go Env Via VSCode in Linux
source link: https://en.liqiang.io/post/install-and-configure-go-env-via-vscode-in-linux?lang=US_EN
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
0. Overview
Introduces the general Linux environment installation method of VSCode and the process of configuring a Go developer environment.
1. Installation
1.1. Download the executable file
Open the official website and download the corresponding tarball: download address
1.2. Unzip the executable file
[[email protected]]# tar -zxvf code-stable-x64-1602601238.tar.gz -C /opt/
[[email protected]]# chmod +x /opt/VSCode-linux-x64/code
[[email protected]]# ln -s /opt/VSCode-linux-x64/code /usr/local/bin/code
1.3. Start vscode
[[email protected]]# code
Figure 1:vscode open page |
---|
2. Configure Remote Developer
2.1. Install client plugin
Using:Ctrl + Shift + P
open command tool,and execute following two commands:
[[email protected]]# ext install ms-vscode-remote.vscode-remote-extensionpack
[[email protected]]# ext install ms-vscode-remote.vscode-remote-extensionpack
2.2. Install server plugin
VSCode A variety of remote tools are supported, I chose the SSH method, in addition to SSH there are:
- Container
- Github Codespaces
Assume here that my remote machine is:10.0.63.154
[[email protected]]# ssh-copy-id [email protected] # Configure loginwith password
2.3. Connect remote machine
3. Install Go Develop Environment
3.1 Install Go Plugin
Using shortcut Ctrl + Shift + X
to open the plugin page,and search Go plugin,then click install:
Figure 2:Install Go lang plugin |
---|
3.2 Install Go Tools
Open the command tools windows by shortcut Ctrl + Shift + P
,Search “Go: Install/Update Tools”
Figure 3:Install Go Tools |
---|
And then select all,Click “OK” and then install:
Figure 4:Choose Go Tools |
---|
4. Debug Go Application by dlv
Now you can start configuring the Go debugging tools.
4.1 Configure file
Open the debugging tool via the shortcut key Ctrl + Shift + D
and find the link inside:
Figure 5:Add debug configure |
---|
If you can’t find it,you can also open the .vscode
directory below the root directory,and create a new file named:launch.json
,wirte the following content into the file:
[[email protected]]# cat .vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/apps/main.go",
"env": {
"env":"test"
},
"": "envFile\": \"${workspaceFolder}/.env",
"args": []
}
]
}
Now, you have finish your configure。
4.2 Add breakpoint
It’s so easy to add the breakpoint,just click you mouse near the code line:
Figure 6:Add breakpoint |
---|
4.3 Begin debug
You can start to debug you code via shortcut F5
,and can also open the debug window and click Run button to debug:
Figure 7:Debug Code |
---|
Then, after stopping at the breakpoint, you can choose whether to step or skip:
Figure 8:Debug method |
---|
5. Frequent shortcuts
5.1 Direct shortcut
Ctrl + Shift + X
:Open plugin windowCtrl + Shift + P
:Open command windowCtrl + Shift + D
:Open debug window
5.2 Shortcut plugins
- Add tag for struct fields
Figure 9:Autofill struct fields |
---|
auto fill struct fields
go get -u github.com/davidrjenni/reftools/cmd/fillstruct
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK