coderef

Go Quick Reference

Go essentials: variables, slices, maps, structs, interfaces, errors, goroutines, channels and the go tool.

6 sections · 39 snippets · updated Oct 14, 2026

Click any snippet to copy it.

Basics

Programs and variables.

  • Hello world
  • Variables
  • Multiple assignment
  • Print formatted
  • Convert

Slices & maps

Collections.

  • Slice
  • Make with length
  • Slice of a slice
  • Loop
  • Sort
  • Contains
  • Reverse
  • Map
  • Check a key
  • Delete a key

Control flow

Conditions and loops.

  • If with init
  • For (the only loop)
  • Range over an integer (1.22+)
  • Switch
  • Defer

Functions, structs & interfaces

Types and methods.

  • Function with multiple returns
  • Struct
  • Method
  • Pointer receiver
  • Interface
  • Generics
  • Struct tags (JSON)

Errors & concurrency

Error handling, goroutines and channels.

  • Check an error
  • Wrap an error
  • Check error type
  • Goroutine
  • Channel
  • Wait group
  • Select

Go tool

Build, test and modules.

  • Start a module
  • Run / build
  • Test
  • Add / tidy dependencies
  • Format / vet

← All quick references