Skip to content
iamnoobs

Beginner to advanced · 13 modules · 39 lessons

Learn Go (Golang): Beginner to Advanced

Learn Go from first principles through packages, error handling, interfaces, generics, testing, concurrency, HTTP APIs, and production practices with short lessons, guided code, quizzes, checkpoints, and a capstone.

Who this is for: Beginners and developers who want to learn Go for command-line tools, backend services, networked applications, automation, and concurrent systems.

Prerequisites: No prior Go experience is required. Basic familiarity with files and running commands is helpful. Examples use the standard library where practical; some examples are snippets rather than standalone files and are explanatory rather than executed on this website.

Meet Go and write your first program

Packages, imports, and main

A Go executable starts in package main at the main function.

Go source files declare a package. A runnable command uses package main and defines func main() as its entry point. Imported packages provide reusable functionality, such as fmt for formatted input and output.

Go intentionally keeps syntax compact. Names imported but not used cause compilation errors, which encourages removing stale dependencies and keeping examples tidy.

Guided example

Read through this example; code examples are for learning and are not executed on this site.

package main

import "fmt"

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

Relevance quest · +10 XP

Which combination identifies the entry point of a standard Go executable?

Choose your answer

Mark this lesson complete when you are ready.

Module checkpoint: Meet Go and write your first program

Create main.go that prints your name, the Go version you are learning, and three short lines of output. Format it with gofmt and run it with go run.

After this module, you can:

  • Describe the roles of the Go compiler, runtime, and go tool.
  • Recognize package main and the main function in an executable.
  • Run a small program and use compiler feedback to fix errors.

Full curriculum

What you will learn

1. Meet Go and write your first program

Beginner

Understand Go's design, toolchain, program structure, and basic console output.

  1. Packages, imports, and main

    A Go executable starts in package main at the main function.

  2. Run, build, and format Go code

    The go tool runs, builds, formats, and tests Go projects.

  3. Comments, names, and basic syntax

    Go uses case-sensitive identifiers and familiar line and block comments.

Module checkpoint: Create main.go that prints your name, the Go version you are learning, and three short lines of output. Format it with gofmt and run it with go run.

2. Variables, types, and constants

Beginner

Declare values, select suitable types, and understand initialization, constants, and conversions.

  1. Variables and short declarations

    Variables have declared types, and := infers a local variable's type.

  2. Built-in types and zero values

    Go provides numeric, Boolean, string, and byte/rune types for common data.

  3. Constants and type conversions

    Constants name fixed values, and Go requires explicit conversions between many distinct types.

Module checkpoint: Write a small receipt calculation that uses a constant tax rate, an integer item count, a floating-point price, and an explicit conversion where needed.

3. Operators, decisions, and control flow

Beginner

Evaluate expressions, make decisions, and repeat work with Go's control-flow statements.

  1. Arithmetic and comparison operators

    Operators combine values into calculations and Boolean comparisons.

  2. Conditions with if and else

    Go conditions use if and may include an initializer before the condition.

  3. Switch statements and for loops

    Go uses switch for multiway branching and for as its looping construct.

Module checkpoint: Build a small grade classifier using if/else and switch. Then print numbers in a range using for and identify the condition that stops the loop.

4. Arrays, slices, and iteration

Beginner

Store ordered values and understand the crucial differences between arrays and slices.

  1. Fixed-size arrays

    An array has a fixed length that is part of its type.

  2. Slices, make, and append

    A slice describes a variable-length view over an underlying array.

  3. Iterate with range and understand copying

    range visits elements in arrays, slices, maps, strings, and channels.

Module checkpoint: Write a function that accepts a slice of integers and returns the minimum and maximum. Test empty, one-element, and multi-element slices, and document how an empty slice is handled.

5. Functions, multiple returns, and errors

Beginner

Design reusable functions, pass values deliberately, and handle failures through Go's error convention.

  1. Parameters and return values

    Functions make behavior reusable and define clear inputs and outputs.

  2. Multiple returns and early exits

    Multiple return values can make success and failure paths explicit.

  3. Create and handle errors

    Go usually represents expected failures with explicit error return values.

Module checkpoint: Write a function that calculates an average and returns an error for an empty input. Write callers that handle both valid results and failures.

6. Maps, structs, and methods

Intermediate

Model domain data with structs, look up values with maps, and attach behavior through methods.

  1. Maps and safe lookups

    Maps associate keys with values and report whether a key exists.

  2. Structs and composite literals

    Structs group named fields into an application-specific data type.

  3. Methods and receivers

    Methods associate behavior with a defined type through a receiver parameter.

Module checkpoint: Create a Task struct, use a map to look up tasks by ID, and add methods to mark a task complete. Handle lookups for IDs that do not exist.

7. Pointers, interfaces, and composition

Intermediate

Understand addresses, express behavior with interfaces, and combine types without class inheritance.

  1. Pointers and addresses

    A pointer stores the address of a value, and the zero value of a pointer is nil.

  2. Interfaces and implicit implementation

    A type implements an interface by providing its required methods.

  3. Composition and embedding

    Go encourages composing types from smaller values and behaviors rather than class inheritance.

Module checkpoint: Define a small storage interface, implement it with an in-memory map-backed type, and write a function that accepts only the interface it needs.

8. Packages, modules, and developer tooling

Intermediate

Organize code into packages and modules and use the Go toolchain for repeatable development.

  1. Go modules and dependencies

    A module defines a project and records its dependency requirements.

  2. Packages and exported APIs

    Packages group related code, and capitalization controls which names are exported.

  3. Formatting, vetting, and testing commands

    Standard tools catch style problems, suspicious constructs, and regressions.

Module checkpoint: Create a module with a reusable package and a main package. Export one function, keep a helper unexported, then run gofmt, go test ./..., and go vet ./....

9. Strings, JSON, and file handling

Intermediate

Transform text safely, encode structured data, and perform file operations with explicit error handling.

  1. Strings, bytes, and Unicode

    Go strings store bytes, so byte indexing and Unicode code-point iteration differ.

  2. Encode and decode JSON

    The encoding/json package converts between JSON data and Go values.

  3. Read and write files

    File operations return errors that must be handled and resources that must be closed.

Module checkpoint: Create a Task struct, encode a few tasks as JSON, save them to a file, load them back, and handle both filesystem and JSON decoding errors.

10. Generics, testing, and reusable code

Intermediate

Write generic helpers where useful and protect program behavior with automated tests and benchmarks.

  1. Type parameters and constraints

    Generics let functions and types operate on multiple types that meet a constraint.

  2. Unit tests and table-driven tests

    Go tests are functions named TestXxx in files ending with _test.go.

  3. Benchmarks, coverage, and fuzzing

    Different test tools investigate performance, execution coverage, and unexpected inputs.

Module checkpoint: Write table-driven tests for a slice-processing function. Run go test ./..., inspect coverage, and add a benchmark only for a performance question you actually need to answer.

11. Goroutines, channels, and synchronization

Advanced

Run concurrent tasks safely and coordinate them using channels, mutexes, and cancellation-aware patterns.

  1. Goroutines and concurrent work

    A goroutine is a lightweight unit of concurrent execution managed by the Go runtime.

  2. Channels and select

    Channels communicate values between goroutines and can coordinate work.

  3. Wait groups, mutexes, and race detection

    Synchronization tools coordinate completion and protect shared state.

Module checkpoint: Launch several workers, gather their results, and then modify a shared counter under a mutex. Run the race detector and explain how the code avoids deadlock and goroutine leaks.

12. Context, HTTP, and API clients

Advanced

Build reliable networked code with HTTP handlers, request contexts, timeouts, and explicit response handling.

  1. Context, deadlines, and cancellation

    Context carries cancellation signals, deadlines, and request-scoped values across API boundaries.

  2. HTTP clients and response handling

    The net/http package provides HTTP clients and servers with explicit response and error handling.

  3. HTTP handlers and JSON APIs

    Handlers map HTTP requests to validated application behavior and responses.

Module checkpoint: Build a small HTTP health endpoint and a JSON endpoint. Add request validation, explicit status codes, timeouts on client calls, and tests for invalid methods and malformed input.

13. Performance, diagnostics, and release readiness

Advanced

Use profiles and diagnostics to find real bottlenecks, structure applications for testing, and prepare dependable builds.

  1. Measure and profile performance

    Benchmarks and profiles help identify the operations that consume time or memory.

  2. Logging, tracing, and diagnostics

    Useful diagnostics preserve enough context to explain failures without exposing secrets.

  3. Application structure and release builds

    Clear boundaries, repeatable checks, and explicit configuration make Go programs easier to maintain and ship.

Module checkpoint: Review the capstone for clear package boundaries, checked errors, useful logs, repeatable tests, and documented build steps. Run the full test and vet commands before building the release executable.

Put it together

Go capstone: Personal Study Tracker

Build a command-line study tracker that creates, lists, completes, filters, and deletes study tasks. Model tasks with structs, use slices and maps where appropriate, validate input, store data in JSON, and add tests. As an extension, expose a small HTTP API with request validation and graceful shutdown.

  1. 1Create a Go module and define a Task type with an ID, title, completion status, and suitable timestamps or category fields.
  2. 2Implement focused functions for adding, listing, completing, filtering, and deleting tasks; return errors for invalid input and missing IDs.
  3. 3Persist tasks as JSON, check all file and encoding errors, and define how the application behaves when the file is missing or malformed.
  4. 4Add table-driven tests for normal, empty, invalid, and boundary cases; run go test ./... and go vet ./....
  5. 5Optionally expose tasks through an HTTP API with validation, explicit status codes, request contexts, and tests; document how to build and run the application.

Progress is saved in this browser when local storage is available. You can continue without an account; changing browsers or clearing browser data may remove saved progress. Examples are not executed by the site.