See Effective Go for tips on writing clear, idiomatic Go code.
https://go.dev/doc/effective_go
Visit the documentation page for a set of in-depth articles about the Go language and its libraries and tools.
Using Go Modules
https://go.dev/blog/using-go-modules
https://github.com/golang/go/wiki/SettingGOPATH
go env -w GOPATH=/Users/username/go
You can use the go env command to portably set the default value for an environment variable for future go commands:
go env -w GOBIN=/Users/username/go/bin
To unset a variable previously set by go env -w, use go env -u:
go env -u GOBIN
Add to OS env PATH
export PATH=$PATH:/Users/username/go/bin
https://pkg.go.dev/golang.org/x/tools/cmd/goimports
install
go install golang.org/x/tools/cmd/goimports@latest
usage
goimports -w filename.go
https://go.dev/doc/gopath_code
GOPATH and Modules
When using modules, GOPATH is no longer used for resolving imports. However, it is still used to store downloaded source code (in GOPATH/pkg/mod) and compiled commands (in GOPATH/bin).