Tutorial

Go Tutorial

A practical tutorial to get you productive with Go for backend development, CLI tools, and cloud-native applications. Covers fundamentals, concurrency, testing, and the standard library.

Tutorial·Difficulty: Intermediate·13 chapters·Updated Apr 19, 2026

Chapters

About this tutorial

A practical tutorial to get you productive with Go.

Who This Is For

  • Developers with experience in other languages
  • Those wanting to learn Go for backend development, CLI tools, or cloud-native applications
  • Anyone looking for a practical, example-driven guide

Contents

Fundamentals

  1. Introduction - What is Go, installation, first program
  2. Basics - Variables, types, operators, strings
  3. Control Flow - If, for, switch, defer
  4. Functions - Functions, closures, methods
  5. Collections - Arrays, slices, maps

Object-Oriented Go

  1. Structs & Methods - Structs, methods, embedding
  2. Interfaces - Interfaces, polymorphism, type assertions

Core Concepts

  1. Error Handling - Error patterns, wrapping, custom errors
  2. Concurrency - Goroutines, channels, sync package

Ecosystem

  1. Packages & Modules - Project structure, dependencies
  2. Testing - Unit tests, benchmarks, fuzzing
  3. Standard Library - Essential stdlib packages

Mastery

  1. Best Practices - Idioms, patterns, anti-patterns

How to Use This Tutorial

  1. Read sequentially for a complete learning path
  2. Jump to specific topics if you need a reference
  3. Type out the examples - don't just read them
  4. Build something after each section

Quick Reference

Essential Commands

# Create a new project
mkdir myproject && cd myproject
go mod init github.com/username/myproject

# Run a program
go run main.go

# Build an executable
go build

# Run tests
go test ./...

# Format code
go fmt ./...

# Manage dependencies
go mod tidy

Hello World

package main

import "fmt"

func main() {
    fmt.Println("Hello, World!")
}

Common Patterns

// Error handling
result, err := doSomething()
if err != nil {
    return fmt.Errorf("doing something: %w", err)
}

// Goroutine with channel
ch := make(chan string)
go func() {
    ch <- "result"
}()
result := <-ch

// HTTP handler
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    fmt.Fprint(w, "Hello!")
})
http.ListenAndServe(":8080", nil)

Learning Path Suggestions

Backend Developer (2-3 days)

  1. Fundamentals (chapters 1-5)
  2. Structs & Interfaces (6-7)
  3. Error Handling (8)
  4. Standard Library (12) - focus on net/http, encoding/json
  5. Build a REST API

DevOps/CLI Developer (2-3 days)

  1. Fundamentals (chapters 1-5)
  2. Error Handling (8)
  3. Packages & Modules (10)
  4. Standard Library (12) - focus on os, flag, exec
  5. Build a CLI tool

Systems Programmer (1 week)

  1. All fundamentals (1-9)
  2. Deep dive into Concurrency (9)
  3. Standard Library (12) - focus on sync, io, os
  4. Build a concurrent data processor

Additional Resources

Go Version

This tutorial is written for Go 1.21+ and covers features up to Go 1.22.