hello/README.md

70 lines
1.8 KiB
Markdown
Raw Normal View History

2024-05-06 13:47:08 +02:00
A simple `helloworld` for Golang in VsCode.
2024-05-06 11:54:54 +02:00
2024-05-06 13:47:08 +02:00
# Golang the compiler
2024-11-07 22:13:37 +01:00
Download Golang [installer](https://go.dev/dl/). A least on Mac the installer shall be able to deal with [updating OS](https://gist.github.com/Linerre/f11ad4a6a934dcf01ee8415c9457e7b2) `PATH` environment variable with `$GOPATH/bin`.
2024-05-06 13:25:41 +02:00
## Debugger
2024-05-06 13:47:08 +02:00
2024-05-06 13:25:41 +02:00
```bash
go install -v github.com/go-delve/delve/cmd/dlv@latest
```
2024-11-29 16:09:25 +01:00
To install / update the goTools in VsCode:
Click `cmd`+`shift`+`p` and search for _Go: Install/Update tools_
2024-05-06 13:25:41 +02:00
# VsCode IDE
- Install [Visual Studio Code](https://code.visualstudio.com)
- `golang` extension
2024-11-07 22:13:37 +01:00
To launch *VS Code Quick Open* press (Ctrl + P), type: `ext install Go`, hit enter. Follow basic instructions.
2024-05-06 13:25:41 +02:00
# The Project
2024-11-07 22:13:37 +01:00
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:
2024-05-06 13:25:41 +02:00
```go
package main
import "fmt"
func main() {
fmt.Println("Hello World!")
i := 101
fmt.Println(i)
}
```
Some useful hotkeys:
- `Ctrl + Shift + D` - Open Debugger
2024-11-07 22:13:37 +01:00
- `F9` - set or toggle Breakpoint. *Try this line `i := 101`*
- `F5` - Start Debugging or to Run the Application. If asked to select environment: select `Go`
- `F10` - Step Over
- `F11` - Step Into
- `Shift + F11` - Step Out
- `Shift + F5` - Stop Debugging
- `Ctrl + Shift + F5` - Restart Debugging
2024-05-06 13:25:41 +02:00
2024-11-07 22:13:37 +01:00
Typical aka untouched `launch.json`:
2024-05-06 13:25:41 +02:00
```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
}
]
}
```