go doc

  • Run web server: godoc -http=localhost:8888 -index -links
  • View web server: http://localhost:8888
    • Tip: Add ?m=all to URL to show unexported types, funcs, etc.

go test

Run all tests:

  • Run all tests: go test ./...
  • Run all tests in package: go test modulename/pkg/packagename/
  • Run all tests in file: go test path/to/file_test.go

Run subset of tests:

  • Run function tests: go test path/to/file_test.go -run FUNCTION_TEST_NAME
  • Run a single test in function tests: go test path/to/file_test.go -run FUNCTION_TEST_NAME/test_name_here

Tips:

  • Skip test caching with -count 1.
  • Run tests multiple times with -count 10. Useful for finding flaky tests.
  • Add -v for verbose output. Useful for finding test names and whatnot.

go get

Upgrade all dependencies:

docker run -it -v .:/app -w /app golang:DESIRED_GO_VERSION sh  # optional
go list -m -u all | awk '{print $1}' | xargs -n 1 go get -u
go mod tidy