hello/README.md
2024-05-06 13:43:08 +02:00

66 lines
1.6 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Install `Golang`
## Compiler
Download Golang [installer](https://go.dev/dl/). A least on Mac it shall deal with updating your OS `PATH` environment variable with  `$GOPATH/bin`.
## Debugger
```bash
go install -v github.com/go-delve/delve/cmd/dlv@latest
```
# VsCode IDE
- Install [Visual Studio Code](https://code.visualstudio.com)
- `golang` extension
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:
```go
package main
import "fmt"
func main() {
fmt.Println("Hello World!")
i := 101
fmt.Println(i)
}
```
Some useful hotkeys:
- `Ctrl + Shift + D` - Open Debugger
- `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
Typical aka untouched `launch.json` :
```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
}
]
}
```