https://github.com/t3easy/hello-go
Example of the talk https://t3easy.github.io/talks/go-fundamentals/
https://github.com/t3easy/hello-go
Last synced: over 1 year ago
JSON representation
Example of the talk https://t3easy.github.io/talks/go-fundamentals/
- Host: GitHub
- URL: https://github.com/t3easy/hello-go
- Owner: t3easy
- License: gpl-2.0
- Created: 2022-05-10T13:23:30.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-05-10T16:54:57.000Z (about 4 years ago)
- Last Synced: 2025-01-21T00:33:37.453Z (over 1 year ago)
- Language: Go
- Size: 16.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Hello Go!
Example of the talk https://t3easy.github.io/talks/go-fundamentals/
1. ```
go mod init github.com/t3easy/hello-go
```
1. Add main.go and run it
```
go run main.go
```
1. Add test and run it
```
go test ./...
```
1. Install cobra-cli
```
go install github.com/spf13/cobra-cli@latest
```
1. Rename main.go, to temp.go
1. Init module with cobra-cli
```
~/go/bin/cobra-cli init
```
1. Add functionality of previous `main.go` to `cmd/root.go`,
move `main_test.go` to `cmd/root_test.go`
1. Test and run
```
go test ./...
go run main.go
```
1. Add `--name` parameter that defaults to `Go`
1. Module housekeeping
```
go mod tidy
```
1. Add `serve` command and run it
```
~/go/bin/cobra-cli add serve
go run main.go serve
````
1. Move `getMessage` function to `github.com/t3easy/hello-go/internal` with capital `G`!
As we will need it in the `serve` cmd, too.
Run tests to check if nothing is broken.
```
go test ./...
go run main.go --name FooBar
```
1. Add http server for the "API"
```
go run main.go serve
```
Open http://127.0.0.1:4242/
Open http://127.0.0.1:4242/FooBar
1. Add `--port` flag to serve command
1. Build binary
```
go build -o bin
```