This is the first part of the three part practical introduction to Go series. It is written for developers, who have already some experience in other languages and wish to learn and become productive in Go.
This article focuses on setting up a Go development environment, so that you can run and compile Go code locally and are prepared for the next parts of this series, starting with: Language basics.
I love Go, so my perspective might be a bit biased. I also acknowledge that choice of programming language is heavily influenced by personal preference and suitability for the use-case at hand. Having this said, here is why I think Go is a great tool:
- Simplicity by design. This makes it easy to learn and easy to collaborate. Instead of having a multitude of expressions to achieve the same thing (like so many other languages), Go provides only one.
- Concurrency, is a first class citizen! Go offers simple syntax and primitives that allow you to write code that uses all available CPU with little effort or complexity.
- Cross Compilation, is wonderfully easy. Compiling from Linux to Windows, from AMD64 to ARM or vice versa or any combination is a no-brainer.
- Dependency Management, is solved with built-in tooling and works like a charm. The Go authors were not shy to learn from others (mistakes).
- Huge and growing Ecosystem: There are already many very popular (Kubernetes, Docker, ..) software projects in Go, the list keeps growing.
- Built-in Tooling: Go comes with all the tooling you need for compiling, testing, profiing and benchmarking. It’s fun to develop in, not a gazillion of needed tooling options like (cough) others..
- Extensive Standard Library: The Go Standard Library, part of every Go setup, provides everything from working with archives in tar or zip, to encoding/decoding of JSON, CSV, etc, to a fast and powerful HTTP server and client, to working with smart templates - it’s a lot of useful things.
Go language tooling
The first thing you need to have to do any local Go development is the
go binary. Head over to https://golang.org/dl/ and download the installer, then follow the guide for your respective operating system:
Once you followed the steps you should be able to execute
go version from your terminal:
$ go version go version go1.14.6 linux/amd64
That’s it. Go comes with all you need out-of-the-box. The most important commands, which will be used in the following parts of this series, are:
go run: Development tooling to execute your source code
go build: Compile source code into binary files
go test: Run source code tests
go get: Download dependencies (3rd party libraries)
go mod: Handle module concerns, more on that later
Aside from the
go binary, the installation also comes with the source code of Go Standard Library, which we’ll explore in the following articles.
Choose your IDE
If you already have a favorite IDE, chances are there is a good Go plugin or extension available. If not, or if you wish to try out something new consider the following:
Microsoft Visual Studio Code
Relatively lightweight for a full IDE, extremely extensible, huge community & ecosystem.
- IDE: https://code.visualstudio.com/
- Plugin: https://marketplace.visualstudio.com/items?itemName=golang.go
- HowTo: https://code.visualstudio.com/docs/languages/go
IntelliJ: GoLand (or IDEA with plugin)
Full fledged IDE, first class Go integration, heavy weight.
IntelliJ offers two flavours:
Battle tested, fast, very opinionated.
- Plugin: https://github.com/fatih/vim-go
Aside from the above many other editors and IDEs support Go development. To name a few:
- Atom with go-plus plugin
- Sublime Text with GoSublime plugin
- Eclipse with Goclipse extension
- Emacs in GoLangMode
Now that you have an editor of your choice and the Go binaries installed, head over to the next part in the series and get familiar with the language basics.