CURRICULUM PREVIEWRevision 1 · Open for reviewReview the full course
CONNECTING THE PIECES8 min read

Modules and a small Go program

Start with explicit dependencies and a reproducible build.

The idea

A Go module gives packages a stable import path and records dependency versions. Keep the booking domain separate from the executable that wires dependencies. Commit go.mod and go.sum. A package name describes a responsibility; it is not a reason to build a deeply nested folder hierarchy.

Follow the flow

Make it concrete

This excerpt isolates the concept. Connect it to the booking API as you work through the exercise.

Focused example
Go
module example.com/booking

// cmd/api/main.go composes the application.
// internal/booking owns the booking behavior.
// go test ./... checks all module packages.

Decisions that matter

  • A single module is sufficient for many services.
  • Internal packages express repository-local boundaries.
  • Run tests and builds with a pinned Go toolchain in CI.

Your turn

Where should a PostgreSQL connection be constructed, and which package should own booking invariants?

Reveal a worked answer

Construct the pool in the executable composition root and pass a narrow dependency into the booking operation. Keep booking invariants in the booking package so transport and persistence cannot become their only enforcement points.

Keep exploring

One more piece connected.

Mark this lesson complete when you can explain the idea.