Go-Tutorial

module
v0.0.0-...-610d9af Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: GPL-3.0

README

Go-Tutorial drawing

A hands-on path from zero Go to job-ready Go backend engineer: language, concurrency, SQL, REST APIs, frameworks, microservices and the other things Go is used for in industry.

Built for Go 1.27.1+. Every lesson is a runnable program with notes in its comments.

Quick start

go version                               # needs go1.27.1 or newer
go run ./01-fundamentals/01hello         # run one lesson
make help                                # list all helper tasks
make test                                # run every test in the repo

go run ./path/to/lesson compiles and runs the main package in that folder. go build -o bin/app ./path produces a binary instead (bin/ is git-ignored).

Roadmap

Do the tracks in order. Each folder has a README.md with the lesson list and interview questions.

# Track What you learn Why it matters for jobs
01 Fundamentals syntax, types, slices, maps, structs, interfaces, errors, generics, iterators, JSON, testing, modules Every interview starts here
02 Concurrency goroutines, channels, select, sync, context, worker pools, errgroup, race detector Go's killer feature; always asked
03 SQL with SQLite SQL itself, database/sql, transactions, joins, indexes, pagination, sqlx, sqlc, migrations Go shops use raw SQL, not ORMs
04 Web with stdlib net/http, routing, JSON, middleware, slog, HTTP client, graceful shutdown, httptest Std lib is enough for production
05 Capstone: taskapi production REST API: layered layout, auth (Argon2id, JWT + Better Auth-style cookie sessions, GitHub OAuth), sqlc, migrations, tests, Docker Portfolio project for interviews
06 Frameworks same API in chi, Gin, Fiber + comparison Read any codebase you join
07 Microservices gRPC + protobuf, API gateway, tracing, docker-compose, retries, idempotency How bigger companies split systems
08 Other use cases CLI tools, TCP server, WebSockets, crawler, job worker Go is also DevOps / infra / tooling

Extra reading in docs/:

Why SQLite?

Zero setup: the database is a file and the driver (modernc.org/sqlite) is pure Go, so no Docker or C compiler is needed. The SQL is written to be portable; docs/postgres-later.md shows the handful of changes needed to switch to PostgreSQL, which is what most Go jobs use in production.

Tooling used

Tool How you get it
Go 1.27.1+ https://go.dev/dl
sqlc, goose, buf pinned in go.mod as tools → go tool sqlc ... (no global install)
golangci-lint optional locally (https://golangci-lint.run), always runs in CI
Docker only for tracks 05 (image build) and 07 (docker-compose)

Resources

Directories

Path Synopsis
01-fundamentals
01hello command
Lesson 01: Hello, World
Lesson 01: Hello, World
02packages command
Lesson 02: Packages and imports
Lesson 02: Packages and imports
03functions command
Lesson 03: Functions
Lesson 03: Functions
04variables command
Lesson 04: Variables and constants
Lesson 04: Variables and constants
05datatypes command
Lesson 05: Basic data types
Lesson 05: Basic data types
06operators command
Lesson 06: Operators
Lesson 06: Operators
07pointers command
Lesson 07: Pointers
Lesson 07: Pointers
08loops command
Lesson 08: Loops
Lesson 08: Loops
09conditions command
Lesson 09: Conditions (if and switch)
Lesson 09: Conditions (if and switch)
10arrays command
Lesson 10: Arrays
Lesson 10: Arrays
11slices command
Lesson 11: Slices
Lesson 11: Slices
12maps command
Lesson 12: Maps
Lesson 12: Maps
13range command
Lesson 13: range
Lesson 13: range
14strings command
Lesson 14: Strings, runes and bytes
Lesson 14: Strings, runes and bytes
15structs command
Lesson 15: Structs
Lesson 15: Structs
16methods command
Lesson 16: Methods
Lesson 16: Methods
17interfaces command
Lesson 17: Interfaces
Lesson 17: Interfaces
18enums command
Lesson 18: Enums with iota
Lesson 18: Enums with iota
19embedding command
Lesson 19: Embedding and composition
Lesson 19: Embedding and composition
20errors command
Lesson 20: Errors
Lesson 20: Errors
21defer command
Lesson 21: defer, panic and recover
Lesson 21: defer, panic and recover
22closures command
Lesson 22: Closures, function values and functional options
Lesson 22: Closures, function values and functional options
23generics command
Lesson 23: Generics (type parameters)
Lesson 23: Generics (type parameters)
24iterators command
Lesson 24: Iterators and range-over-func (Go 1.23+)
Lesson 24: Iterators and range-over-func (Go 1.23+)
25time command
Lesson 25: The time package
Lesson 25: The time package
26files command
Lesson 26: Working with files
Lesson 26: Working with files
27json command
Lesson 27: JSON with encoding/json
Lesson 27: JSON with encoding/json
28testing command
Lesson 28: Testing
Lesson 28: Testing
28testing/calc
Package calc is a tiny library that exists to be tested.
Package calc is a tiny library that exists to be tested.
29modules command
Lesson 29: Modules and packages
Lesson 29: Modules and packages
29modules/internal/greet
Package greet lives under an internal/ directory.
Package greet lives under an internal/ directory.
29modules/mathx
Package mathx is a normal (public) package: any module may import it.
Package mathx is a normal (public) package: any module may import it.
30modern-go command
Lesson 30: A tour of modern Go (1.22 to 1.27)
Lesson 30: A tour of modern Go (1.22 to 1.27)
02-concurrency
01goroutines command
Lesson 01: Goroutines
Lesson 01: Goroutines
02channels command
Lesson 02: Channels
Lesson 02: Channels
03select command
Lesson 03: select
Lesson 03: select
04sync command
Lesson 04: sync package (Mutex, RWMutex, Once, Map)
Lesson 04: sync package (Mutex, RWMutex, Once, Map)
05atomic command
Lesson 05: sync/atomic
Lesson 05: sync/atomic
06context command
Lesson 06: context
Lesson 06: context
07workerpool command
Lesson 07: Worker pool
Lesson 07: Worker pool
08pipeline command
Lesson 08: Pipelines, fan-out and fan-in
Lesson 08: Pipelines, fan-out and fan-in
09errgroup command
Lesson 09: errgroup
Lesson 09: errgroup
10ratelimit command
Lesson 10: Rate limiting and concurrency limiting
Lesson 10: Rate limiting and concurrency limiting
11race command
Lesson 11: Data races and the race detector
Lesson 11: Data races and the race detector
12synctest
Package debounce is the subject of lesson 12 (testing/synctest).
Package debounce is the subject of lesson 12 (testing/synctest).
13leaks command
Lesson 13: Common concurrency bugs (and their fixes)
Lesson 13: Common concurrency bugs (and their fixes)
03-sql-sqlite
01basics command
Lesson 01: SQL basics, run through Go so you can see every statement and its result.
Lesson 01: SQL basics, run through Go so you can see every statement and its result.
02database-sql command
Lesson 02: database/sql, Go's standard database API.
Lesson 02: database/sql, Go's standard database API.
03prepared command
Lesson 03: placeholders, prepared statements, and SQL injection.
Lesson 03: placeholders, prepared statements, and SQL injection.
04transactions command
Lesson 04: transactions.
Lesson 04: transactions.
05queries command
Lesson 05: the queries you need to know for interviews and real work.
Lesson 05: the queries you need to know for interviews and real work.
06indexes command
Lesson 06: indexes, EXPLAIN QUERY PLAN, and the N+1 query problem.
Lesson 06: indexes, EXPLAIN QUERY PLAN, and the N+1 query problem.
07pagination command
Lesson 07: pagination, OFFSET vs keyset (cursor) pagination.
Lesson 07: pagination, OFFSET vs keyset (cursor) pagination.
08sqlx command
Lesson 08: sqlx, database/sql with the boilerplate removed.
Lesson 08: sqlx, database/sql with the boilerplate removed.
09sqlc command
Lesson 09: sqlc, compile-time checked SQL.
Lesson 09: sqlc, compile-time checked SQL.
10migrations command
Lesson 10: schema migrations with goose.
Lesson 10: schema migrations with goose.
11testing-db
Package store is lesson 11: a small data-access layer (TaskStore) that is easy to test against a REAL database.
Package store is lesson 11: a small data-access layer (TaskStore) that is easy to test against a REAL database.
internal/sqldb
Package sqldb holds the small helpers shared by every lesson in the SQL track: opening a SQLite database with sensible settings and loading the sample schema + data.
Package sqldb holds the small helpers shared by every lesson in the SQL track: opening a SQLite database with sensible settings and loading the sample schema + data.
sql
Package sqlfiles embeds the canonical SQL files of the SQL track.
Package sqlfiles embeds the canonical SQL files of the SQL track.
04-web-stdlib
01server command
Lesson 01: the net/http server
Lesson 01: the net/http server
02routing command
Lesson 02: routing with the Go 1.22+ ServeMux
Lesson 02: routing with the Go 1.22+ ServeMux
03json-api command
Lesson 03: a JSON CRUD API (Tasks) with the standard library only
Lesson 03: a JSON CRUD API (Tasks) with the standard library only
04middleware command
Lesson 04: middleware
Lesson 04: middleware
05client command
Lesson 05: the HTTP client
Lesson 05: the HTTP client
06graceful command
Lesson 06: graceful shutdown
Lesson 06: graceful shutdown
07config command
Lesson 07: configuration, secrets and dependency passing
Lesson 07: configuration, secrets and dependency passing
08structure command
Lesson 08: project structure (a preview of the capstone)
Lesson 08: project structure (a preview of the capstone)
08structure/internal/domain
Package domain holds the core types and errors that every layer speaks.
Package domain holds the core types and errors that every layer speaks.
08structure/internal/handler
Package handler is the HTTP layer: parse the request, call the service, write the response.
Package handler is the HTTP layer: parse the request, call the service, write the response.
08structure/internal/service
Package service holds business rules: validation, normalisation, id and time generation, orchestration of stores.
Package service holds business rules: validation, normalisation, id and time generation, orchestration of stores.
08structure/internal/store
Package store is the persistence layer.
Package store is the persistence layer.
05-projects
taskapi/cmd/api command
Command api runs the taskapi HTTP server.
Command api runs the taskapi HTTP server.
taskapi/internal/auth
Package auth contains the security primitives of the service: password hashing (Argon2id), signed JWTs (stateless bearer auth), opaque random tokens (database-backed sessions, email verification, password reset) and the GitHub OAuth client.
Package auth contains the security primitives of the service: password hashing (Argon2id), signed JWTs (stateless bearer auth), opaque random tokens (database-backed sessions, email verification, password reset) and the GitHub OAuth client.
taskapi/internal/auth/githubtest
Package githubtest is a minimal fake of GitHub's OAuth and REST endpoints for tests.
Package githubtest is a minimal fake of GitHub's OAuth and REST endpoints for tests.
taskapi/internal/config
Package config turns environment variables into a validated Config.
Package config turns environment variables into a validated Config.
taskapi/internal/domain
Package domain holds the application's core types and rules: entities, input validation and the error vocabulary.
Package domain holds the application's core types and rules: entities, input validation and the error vocabulary.
taskapi/internal/httpapi
Package httpapi is the HTTP transport layer: routing, middleware, JSON encoding and the mapping from domain errors to status codes.
Package httpapi is the HTTP transport layer: routing, middleware, JSON encoding and the mapping from domain errors to status codes.
taskapi/internal/mailer
Package mailer sends the transactional emails of the auth flows (verify your email, reset your password).
Package mailer sends the transactional emails of the auth flows (verify your email, reset your password).
taskapi/internal/service
Package service holds the application's business logic: validation, authorization rules ("you may only touch your own projects") and orchestration of repositories.
Package service holds the application's business logic: validation, authorization rules ("you may only touch your own projects") and orchestration of repositories.
taskapi/internal/store
Package store is the persistence layer: it implements the repository interfaces that the service package declares, on top of SQLite (via database/sql) and sqlc-generated queries.
Package store is the persistence layer: it implements the repository interfaces that the service package declares, on top of SQLite (via database/sql) and sqlc-generated queries.
06-frameworks
chi command
Frameworks 2/4: the notes API with chi (github.com/go-chi/chi/v5).
Frameworks 2/4: the notes API with chi (github.com/go-chi/chi/v5).
fiber command
Frameworks 4/4: the notes API with Fiber v3 (github.com/gofiber/fiber/v3).
Frameworks 4/4: the notes API with Fiber v3 (github.com/gofiber/fiber/v3).
gin command
Frameworks 3/4: the notes API with Gin (github.com/gin-gonic/gin).
Frameworks 3/4: the notes API with Gin (github.com/gin-gonic/gin).
stdlib command
Frameworks 1/4: the notes API with ONLY the standard library (net/http).
Frameworks 1/4: the notes API with ONLY the standard library (net/http).
07-microservices
cmd/demo command
Command demo runs the WHOLE system in one process and walks through a scripted scenario:
Command demo runs the WHOLE system in one process and walks through a scripted scenario:
gateway command
Command gateway runs the API gateway, the public entry point.
Command gateway runs the API gateway, the public entry point.
gateway/gatewaysvc
Package gatewaysvc is the API gateway: the single public entry point in front of the internal services.
Package gatewaysvc is the API gateway: the single public entry point in front of the internal services.
internal/sqlitedb
Package sqlitedb opens a SQLite database with the settings every service in this track uses.
Package sqlitedb opens a SQLite database with the settings every service in this track uses.
internal/svc
Package svc holds the small pieces every service's main and HTTP stack needs: process lifecycle (signals, graceful shutdown), env-var config, JSON responses, request IDs and access logging.
Package svc holds the small pieces every service's main and HTTP stack needs: process lifecycle (signals, graceful shutdown), env-var config, JSON responses, request IDs and access logging.
internal/telemetry
Package telemetry builds the OpenTelemetry tracing pieces every service in this track shares.
Package telemetry builds the OpenTelemetry tracing pieces every service in this track shares.
orders-svc command
Command orders-svc runs the orders HTTP service.
Command orders-svc runs the orders HTTP service.
orders-svc/orderssvc
Package orderssvc is the orders microservice: an HTTP/JSON API backed by its own SQLite database.
Package orderssvc is the orders microservice: an HTTP/JSON API backed by its own SQLite database.
users-svc command
Command users-svc runs the users gRPC service.
Command users-svc runs the users gRPC service.
users-svc/userssvc
Package userssvc is the users microservice: a gRPC server that owns user data.
Package userssvc is the users microservice: a gRPC server that owns user data.
08-use-cases
01cli command
Use case 01: a command-line tool ("tasks") with only the standard library.
Use case 01: a command-line tool ("tasks") with only the standard library.
02tcp-chat command
Use case 02: a raw TCP chat server (net package, no HTTP, no frameworks).
Use case 02: a raw TCP chat server (net package, no HTTP, no frameworks).
03websocket command
Use case 03: real-time chat over WebSockets (github.com/coder/websocket).
Use case 03: real-time chat over WebSockets (github.com/coder/websocket).
04crawler command
Use case 04: a concurrent, polite web crawler.
Use case 04: a concurrent, polite web crawler.
05jobqueue command
Use case 05: a background job queue backed by SQLite.
Use case 05: a background job queue backed by SQLite.
06fileproc command
Use case 06: a concurrent file-processing pipeline (streaming CSV, fan-out / fan-in).
Use case 06: a concurrent file-processing pipeline (streaming CSV, fan-out / fan-in).
07pprof command
Use case 07: profiling and benchmarking (finding out WHY Go code is slow).
Use case 07: profiling and benchmarking (finding out WHY Go code is slow).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL