Learning Go
Table of Contents generated with DocToc
Getting Started
To get started, either … or …
- Work through For the Love of Go: Fundamentals - addresses complete beginners (I have not read it yet).
- Learn Go with Tests - helped me as an experienced developer to learn Go quickly.
Where to go next?
Practice some code katas, follow the documents listed in the section General Aspects and inspect the Package Libraries.
Prerequisites
Installing Go
- Mac users: Install Go in Learn Go with Tests
- Other users: Go Download and Installation
- Set GOPATH
- Install Golint
- JetBrains Goland - also available for free in JetBrains’ Early Access Program
- Visual Studio Code
- Go - Extension by the Go Team at Google. Follow installation instructions below.
- Getting Started with VS Code Go - An 8 min introduction video into using the VS Code Go extension
- GitHub: golang/vscode-go/docs/features.md - Overview and detailed documentation of the Go extension features.
- Tools - Go extension instructions on how to install the required Go tools (tl;dr
Go: Install/Update Tools
command). - Go Debugging Documentation - Explains how to attach the Go extension to Delve, the go debugger.
- Test Explorer UI - Test Explorer for Visual Studio Code
- Go Test Explorer - Required Test Explorer adapter for Go.
- To use VS Code’s native testing UI instead by setting
testExplorer.useNativeTesting
to true in your VS Code settings
- Go Outliner - Shows Go file outline in a sidebar. Requires
go get -u github.com/766b/go-outliner
.
- Go - Extension by the Go Team at Google. Follow installation instructions below.
Installation Notes
- on the Mac I needed to add
$HOME/go/bin
to my$PATH
manually (~/.zshrc
)
Installing Go Tools
go get -u golang.org/x/tools/...
Uninstalling the Go Package on macOS
Language Tools
Linter
Check whether error returns are handeled correctly in all method calls:
go get -u github.com/kisielk/errcheck
errcheck
Heuristic Source Code Check: go vet
- Go Command vet - Examines suspicious constructs.
Go Frameworks, Libraries and Software
Exploration Tools
Package Libraries
- pkg.go.dev - Search the centralized and curated resources from across the Go ecosystem.
- Go.dev: About - How to add your package documentation to Go.dev.
- The Go Standard Library
- Awesome Go
Frequently used Packages
Testing
- Ginkgo - A Golang BDD Testing Framework.
- Getting Started with BDD in Go Using Ginkgo - Introduction into the BDD Framework Ginkgo.
- Package testify - Documentation for assert, mock, suite statements (GitHub: stretchr / testify)
- David Cheney: How to write benchmarks in Go - Introduction to benchmarking.
- Package quick - Property based testing (quickcheck / quick.Check).
- Package fuzz(beta) - Fuzzing = automated testing which continuously manipulates inputs to a program to find issues such as panics or bugs.
- Package httptest - Utilities for HTTP testing.
- Package mattetti / filebuffer - byte buffer backed file-like interfaces, in-memory alternative to io.File
Parsing XML
- Package encoding/xml - Simple XML 1.0 parser.
- XML to Go - Create a Go struct from an XML document to facilitate reading XML.
- GitHub: miku / zek
Miscellaneous
- Package fmt - Formatted I/O with functions analogous to C’s printf and scanf.
- Package bufio - Buffered I/O.
Go Specific Details
General Aspects
-
A Tour of Go - An interactive tutorial.
-
How to Write Go Code - Demonstrates the development of a simple Go package inside a module and introduces the go tool.
- Using Go Modules - How to setup a Go module and manage dependencies.
- Effective Go - Tips for writing clear, idiomatic Go code.
-
The Go Language Specification - The reference manual for Go.
-
Dave Cheney: Five suggestions for setting up a Go project - Package conventions.
-
Go Code Review Comments - Good practices for Go.
-
Mitchell Hashimoto: Advanced Testing with Go - Slidedeck with various aspects of testing.
-
Kyle Quest: 50 Shades of Go: Traps, Gotchas, and Common Mistakes for New Golang Devs
- Oleg Zaytsev and others: Unexpected Go - Unexpected golang behaviors.
Slices, Errors and Reflection
-
Dave Cheney: Constant errors
-
Rob Pike: The Laws of Reflection
Go Maps
- Dave Cheney: If a map isn’t a reference variable, what is it?
- Andrew Gerrand: Go maps in action in The Go Blog
defer
- Inanc Gumus: Go Defer Simplified with Practical Visuals
- Inanc Gumus: 5 Gotchas of Defer in Go — Part I
- Inanc Gumus: 5 More Gotchas of Defer in Go — Part II
- Inanc Gumus: 5 More Gotchas of Defer in Go — Part III
Concurrency
- Chris James: Concurrency, Goroutines, Channels, Race Detection and Anonymous Functions
- Rick Beton: Use a sync.Mutex or a channel?
- Sameer Ajmani: Go Concurrency Patterns: Context
- Go package context
- Michael Štrba: Context should go away for Go 2
- Jack Lindamood: How to correctly use context.Context in Go 1.7
Tools Easing the Programmer’s Life
- Gitpod: Go Quickstart - Quickly setup a free, cloud hosted go development environment.