Compare commits

...

2 Commits

Author SHA1 Message Date
61de79b764 Tests 2025-06-06 22:27:43 +02:00
5799ca4872 launch.json and build tasks.json 2025-06-06 22:27:24 +02:00
8 changed files with 114 additions and 12 deletions

4
.gitignore vendored
View File

@ -37,3 +37,7 @@
# Go workspace file
go.work
# MacOS
.DS_Store
bin/*

24
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceRoot}",
"env": {},
"args": [],
"showLog": true,
},
{
"name": "Build & Run",
"type": "go",
"request": "launch",
"mode": "exec",
"program": "${workspaceFolder}/bin/hello",
"console": "integratedTerminal",
"preLaunchTask": "go build",
},
]
}

12
.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,12 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "go build",
"type": "shell",
"command": "go build -o bin/hello ./...",
"group": "build",
"problemMatcher": ["$go"]
}
]
}

View File

@ -30,15 +30,18 @@ package main
import "fmt"
func main() {
fmt.Println("Hello World!")
i := 101
fmt.Println(i)
name := "World"
fmt.Println(getGreeting(name))
}
func getGreeting(name string) string {
return fmt.Sprintf("Hello, %s!", name)
}
```
Some useful hotkeys:
- `Ctrl + Shift + D` - Open Debugger
- `F9` - set or toggle Breakpoint. *Try this line `i := 101`*
- `F9` - set or toggle Breakpoint. *Try this line `name := "World"`*
- `F5` - Start Debugging or to Run the Application. If asked to select environment: select `Go`
- `F10` - Step Over
- `F11` - Step Into
@ -57,14 +60,36 @@ Typical aka untouched `launch.json`:
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceRoot}",
"env": {},
"args": [],
"showLog": true
"showLog": true,
}
]
}
```
```
# Custom build task
Create `tasks.json`:
```json
{
"version": "2.0.0",
"tasks": [
{
"label": "go build",
"type": "shell",
"command": "go build -o bin/tui ./...",
"group": "build",
"problemMatcher": ["$go"],
}
]
}
```
Add this line to the desired run command in your `launch.json`
```json
"preLaunchTask": "go build",
```

9
go.mod
View File

@ -1,3 +1,12 @@
module example/hello
go 1.22.2
require github.com/test-go/testify v1.1.4
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.10.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

12
go.sum Normal file
View File

@ -0,0 +1,12 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/test-go/testify v1.1.4 h1:Tf9lntrKUMHiXQ07qBScBTSA0dhYQlu83hswqelv1iE=
github.com/test-go/testify v1.1.4/go.mod h1:rH7cfJo/47vWGdi4GPj16x3/t1xGOj2YxzmNQzk2ghU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@ -3,7 +3,10 @@ package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
i := 101
fmt.Println(i)
name := "Worlds"
fmt.Println(getGreeting(name))
}
func getGreeting(name string) string {
return fmt.Sprintf("Hello, %s!", name)
}

13
hello_test.go Normal file
View File

@ -0,0 +1,13 @@
package main
import (
"testing"
"github.com/test-go/testify/require"
)
func Test_getGreeting(t *testing.T) {
t.Run("success", func(t *testing.T) {
require.Equal(t, "Hello, World!", getGreeting("World"))
})
}