From d097b0c6a1f35ff6790386de74941f4428ec5b7f Mon Sep 17 00:00:00 2001 From: djmil Date: Mon, 6 May 2024 13:25:41 +0200 Subject: [PATCH] code & readme --- .gitignore | 2 ++ README.md | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- go.mod | 3 +++ hello.go | 9 ++++++++ 4 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 go.mod create mode 100644 hello.go diff --git a/.gitignore b/.gitignore index a304625..d957ba8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +.obsidian/* + # ---> VisualStudioCode .vscode/* !.vscode/settings.json diff --git a/README.md b/README.md index 0f69dba..98edc82 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,66 @@ -# hello +ls# Install `Golang` -Golang + VsCode \ No newline at end of file +## 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 + } + ] +} +``` \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..2e0d7b5 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module example/hello + +go 1.22.2 diff --git a/hello.go b/hello.go new file mode 100644 index 0000000..58fb8b3 --- /dev/null +++ b/hello.go @@ -0,0 +1,9 @@ +package main + +import "fmt" + +func main() { + fmt.Println("Hello, World!") + i := 101 + fmt.Println(i) +}