Introduction
About this book
I am writing this book because I find it easier to learn new technologies if the examples are in a language which I already know. For example, learning Test Driven Development is difficult as most of the books use Java as the examples, whereas I am primarily a PHP developer.
I also prefer to learn from books, rather than videos. I think it's a shame that technical books are not as popular as they used to be, either in paper or electronic form.
This book is currently a work in progress, and therefore may contain errors or missing chapters.
This focus of this book is to teach you about how to write Go to run on your local machine. It does not (yet) cover the deployment of Go apps, containerisation etc.
Assumptions
Whilst this is an introductory book on Go, I am making some assumptions about your knowledge, including:
- You are familiar with PHP and use it as your primary development language.
- You are comfortable with using the command line.
- You are using the latest version of Go (1.23).
Whilst older versions of Go should compile most of the code examples, there will be some which only work on later versions of Go. For example, the slices.Clone
function was added in Go 1.21.
Installing Go
There are several ways you can install Go, and I won't repeat all the instructions here. My general recommendations are:
- Linux: Install the go Snap. This is supported by Canonical and regularly updated.
- macOS: Install the go formula via Homebrew.
- Windows: Use the official installer from go.dev.
If you are using Visual Studio Code, you should install the golang.Go extension.
Testing your installation
Once you have Go installed, you can test it by running the version subcommand:
$ go version
You should see output similar to:
go version go1.23.1 linux/amd64
linux/amd64
will be replaced by your operating system and CPU architecture.