Skip to content

t3easy/hello-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hello Go!

Example of the talk https://t3easy.github.io/talks/go-fundamentals/

  1. go mod init github.com/t3easy/hello-go
    
  2. Add main.go and run it
    go run main.go
    
  3. Add test and run it
    go test ./...
    
  4. Install cobra-cli
    go install github.com/spf13/cobra-cli@latest
    
  5. Rename main.go, to temp.go
  6. Init module with cobra-cli
    ~/go/bin/cobra-cli init
    
  7. Add functionality of previous main.go to cmd/root.go,
    move main_test.go to cmd/root_test.go
  8. Test and run
    go test ./...
    go run main.go
    
  9. Add --name parameter that defaults to Go
  10. Module housekeeping
    go mod tidy
    
  11. Add serve command and run it
    ~/go/bin/cobra-cli add serve
    go run main.go serve
    
  12. 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
    
  13. 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
  14. Add --port flag to serve command
  15. Build binary
    go build -o bin
    

Releases

No releases published

Packages

No packages published

Languages