install-go.md
The official installation instructions for Go are available here.
Go 1.11 introduced Modules. This approach is the default build mode since Go 1.16, therefore the use of GOPATH is not recommended.
Modules aim to solve problems related to dependency management, version selection and reproducible builds; they also enable users to run Go code outside of GOPATH.
Using Modules is pretty straightforward. Select any directory outside GOPATH as the root of your project, and create a new module with the go mod init command.
A go.mod file will be generated, containing the module path, a Go version, and its dependency requirements, which are the other modules needed for a successful build.
If no <modulepath> is specified, go mod init will try to guess the module path from the directory structure. It can also be overridden by supplying an argument.
mkdir my-project
cd my-project
go mod init <modulepath>
A go.mod file could look like this:
module cmd
go 1.16
The built-in documentation provides an overview of all available go mod commands.
go help mod
go help mod init
An improvement over the default linter can be configured using GolangCI-Lint.
This can be installed as follows:
brew install golangci-lint
A big emphasis of this book is the importance of refactoring.
Your tools can help you do bigger refactoring with confidence.
You should be familiar enough with your editor to perform the following with a simple key combination:
go fmt. Your editor should run this on every file saved.In addition, to help you work with your code, you should be able to:
Mastering your tools will help you concentrate on the code and reduce context switching.
At this point, you should have Go installed, an editor available, and some basic tooling in place. Go has a very large ecosystem of third-party products. We have identified a few useful components here. For a more complete list, see https://awesome-go.com.