Golang + VsCode
|
|
||
|---|---|---|
| .gitignore | ||
| go.mod | ||
| hello.go | ||
| LICENSE | ||
| README.md | ||
A simple helloworld for Golang in VsCode.
Golang the compiler
Download Golang installer. A least on Mac the installer shall be able to deal with updating OS PATH environment variable with $GOPATH/bin.
Debugger
go install -v github.com/go-delve/delve/cmd/dlv@latest
VsCode IDE
- Install Visual Studio Code
golangextension To launch VS Code Quick Open press (Ctrl + P), type:ext install Go, hit enter. Follow basic instructions.
The Project
Inside Visual Studio Code Open Folder Ctrl + Shift + E , e.g.: $USER\code\hello\. Then Open hello.go from that folder. Or make new file (Ctrl + N) and save it on this folder:
package main
import "fmt"
func main() {
fmt.Println("Hello World!")
i := 101
fmt.Println(i)
}
Some useful hotkeys:
Ctrl + Shift + D- Open DebuggerF9- set or toggle Breakpoint. Try this linei := 101F5- Start Debugging or to Run the Application. If asked to select environment: selectGoF10- Step OverF11- Step IntoShift + F11- Step OutShift + F5- Stop DebuggingCtrl + Shift + F5- Restart Debugging
Typical aka untouched launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceRoot}",
"env": {},
"args": [],
"showLog": true
}
]
}