GoMason

Free · Open source · Work in progress

Learn Go by building
a real ORM.

Most Go tutorials stop at a todo list. This one ends with a working PostgreSQL ORM — struct-tag schemas, a generic query builder, an AST loader, and a migration engine that diffs your code against a live database.

In masonry, a course is one horizontal row of stones. A wall is raised course by course. So is this.

what you will have written by the end
// One struct is the source of truth.
type User struct {
    ID    string `po:"id,primaryKey,uuid"`
    Email string `po:"email,varchar(320),unique"`
}

// Queries come back typed. No reflection at the call site.
users, err := builder.Select[User](qb).
    Where(builder.Gte("age", 18)).
    All(ctx)

The courses

15 courses are ready now — about 12 hours. They start at go mod init, assume no Go experience, and every language feature arrives just before the chapter that needs it. 0 more are being written.

Tick one off as you finish it. Progress is stored in your browser, so there is nothing to sign up for.

15 courses ready

~12h to go

Foundations

0/4

The language itself. No ORM yet — just Go, and enough of it to build one.

  1. 01Setting up Go25 minInstall Go, start a module, and learn the six CLI commands you will actually use.go mod init · go run · go build · go test · gofmt · go vet
  2. 02Values and types35 minZero values, the difference between a string, a rune and a byte, and why slices are not arrays.zero values · slices vs arrays · maps · strings, runes, bytes
  3. 03Structs and methods40 minModel data with structs, hang behaviour off it with methods, and pick the right receiver.structs · methods · pointer vs value receivers · composition
  4. 04Errors40 minErrors are values. Sentinels, wrapping, errors.Is and errors.As, defer, and when to panic.error interface · wrapping with %w · errors.Is and errors.As · defer · panic and recover

The sharp tools

0/5

Interfaces, generics, concurrency, reflection. Each one lands right before the chapter that needs it.

  1. 05Interfaces40 minImplicit satisfaction, small interfaces, and how to test database code without a database.implicit interfaces · method sets · type assertions · the nil interface trap
  2. 06Generics45 minType parameters and constraints, and the difference between []any and []User.type parameters · constraints · type inference · when not to use generics
  3. 07Goroutines and concurrency50 minGoroutines, channels, select, and the mutex that guards a shared cache.goroutines · channels · select · sync.RWMutex · context
  4. 08Reflection and struct tags50 minRead a type at runtime, pull values out of it, and parse the tags on its fields.reflect.Type · reflect.Value · struct tags · performance costs
  5. 09Testing45 minTable-driven tests, helpers, benchmarks, and testing code that talks to a database.go test · table-driven tests · t.Helper · fuzzing · testcontainers

Building the ORM

0/6

Every course from here ends with something that runs, and something that is tested.

  1. 10From struct tags to a schema50 minParse `po:"id,primaryKey"` into typed metadata, including the options that a naive comma split shatters.reflection · parsing · table-driven tests
  2. 11The registry40 minCache table metadata once, read it from many goroutines, and never parse the same struct twice.sync.RWMutex · package design · lazy initialisation
  3. 12The query builder60 minWrite Select[T] with a fluent API, and make it testable by separating SQL from execution.generics · fluent APIs · method chaining · SQL placeholders
  4. 13Executing queries with pgx65 minConnect, run the SQL you built, and scan rows straight into your structs.pgx · connection pools · row scanning · interfaces · batching
  5. 14The AST loader50 minRead struct tags out of source files with go/ast — no compilation required.go/ast · go/parser · file walking
  6. 15Migrations: introspect, diff, plan85 minRead the live schema, diff it against your structs, and emit ordered SQL both ways.information_schema · diffing · topological sort · idempotency