Upgrade version of module

go get -u=patch[user]/[repo]

List variables

go env

See where the overwrite file is for GO

go env GOENV

Test Coverage

go test -v -coverpkg=./... -coverprofile=profile.cov ./... && go tool cover -func profile.cov

Imports sorter

go install

goimports -l -w .

The -l flag tells goimports to print the files with incorrect formatting to the console. The -w flag tells goimports to modify the files in-place. The . specifies the files to be scanned: everything in the current directory and all of its subdirectories.

Go Lint

go install

# run it with:
golint ./...

Go vet

Passing wrong numbers of parameters, assigning values that are never used etc

go vet ./...


Many different tools run over the same directory

golangci-lint run

go generate

Run a command from comments e.g. in a file:

//go:generate mockgen -destination=mocks/mock_foo.go -package=mocks . Foo

the run

go generate

shadow detection

go install

makefile to fmt, lint, vet and build

.DEFAULT_GOAL := build

	go fmt main.go
lint: fmt
	golint main.go
vet: fmt
	go vet main.go
build: vet
	go build main.go

Use a different version of go

go get
go1.15.6 download

Delete new version of go

go1.15.6 env GOROOT
rm -rf $(go1.15.6 env GOROOT)
rm $(go env GOPATH)/bin/go1.15.6