Compare commits
2 Commits
b77b452658
...
61de79b764
Author | SHA1 | Date | |
---|---|---|---|
61de79b764 | |||
5799ca4872 |
4
.gitignore
vendored
4
.gitignore
vendored
@ -37,3 +37,7 @@
|
|||||||
# Go workspace file
|
# Go workspace file
|
||||||
go.work
|
go.work
|
||||||
|
|
||||||
|
# MacOS
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
bin/*
|
24
.vscode/launch.json
vendored
Normal file
24
.vscode/launch.json
vendored
Normal 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
12
.vscode/tasks.json
vendored
Normal 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"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
41
README.md
41
README.md
@ -30,15 +30,18 @@ package main
|
|||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("Hello World!")
|
name := "World"
|
||||||
i := 101
|
fmt.Println(getGreeting(name))
|
||||||
fmt.Println(i)
|
}
|
||||||
|
|
||||||
|
func getGreeting(name string) string {
|
||||||
|
return fmt.Sprintf("Hello, %s!", name)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Some useful hotkeys:
|
Some useful hotkeys:
|
||||||
- `Ctrl + Shift + D` - Open Debugger
|
- `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`
|
- `F5` - Start Debugging or to Run the Application. If asked to select environment: select `Go`
|
||||||
- `F10` - Step Over
|
- `F10` - Step Over
|
||||||
- `F11` - Step Into
|
- `F11` - Step Into
|
||||||
@ -57,14 +60,36 @@ Typical aka untouched `launch.json`:
|
|||||||
"type": "go",
|
"type": "go",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"mode": "debug",
|
"mode": "debug",
|
||||||
"remotePath": "",
|
|
||||||
"port": 2345,
|
|
||||||
"host": "127.0.0.1",
|
|
||||||
"program": "${workspaceRoot}",
|
"program": "${workspaceRoot}",
|
||||||
"env": {},
|
"env": {},
|
||||||
"args": [],
|
"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
9
go.mod
@ -1,3 +1,12 @@
|
|||||||
module example/hello
|
module example/hello
|
||||||
|
|
||||||
go 1.22.2
|
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
12
go.sum
Normal 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=
|
9
hello.go
9
hello.go
@ -3,7 +3,10 @@ package main
|
|||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("Hello, World!")
|
name := "Worlds"
|
||||||
i := 101
|
fmt.Println(getGreeting(name))
|
||||||
fmt.Println(i)
|
}
|
||||||
|
|
||||||
|
func getGreeting(name string) string {
|
||||||
|
return fmt.Sprintf("Hello, %s!", name)
|
||||||
}
|
}
|
||||||
|
13
hello_test.go
Normal file
13
hello_test.go
Normal 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"))
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user