Dev Skills
Go·Section 7 of 15 · 3 lessons · about 3 h 15 min

Modules and packages in Go (Golang)

How Go finds your code, the third-party packages you will meet most, and the four commands to run before every push.

  1. 01Modules, dependencies, and the go command
    How Go finds your code and other people’s, and the commands worth memorising.
  2. 02The packages everyone actually uses
    The well-known third-party libraries, what each is for, and when the standard library is still the better choice.
  3. 03What the famous packages look like in code
    A folder is a package and capitalisation is your access control. Then how a real module splits into many packages, what `internal/` hides, why imports cannot go in a circle, and what the popular libraries look like in code.

What each lesson covers

By the end of this section you will be able to do everything below. Each lesson has runnable Go examples you can edit and run in the browser.

  1. 1. Modules, dependencies, and the go command

    • Create a module with go mod init and explain what go.mod and go.sum each record.
    • Explain why Minimal Version Selection picks the oldest version that satisfies every requirement.
    • Run go vet, gofmt and go test -race the way CI would.

    Remember: The module path is a URL, publishing is a git tag, and a breaking change means a new path with /v2 on the end.

  2. 2. The packages everyone actually uses

    • Explain when the standard library is a better choice than a popular third-party package.
    • Judge a package before adding it, using maintenance, licence and dependency count.
    • Name the usual library for routing, databases, config, logging and testing.

    Remember: Every dependency is code you have to update, audit and explain for as long as you keep it. The stdlib rarely needs justifying.

  3. 3. What the famous packages look like in code

    • Write a module with two packages and call one from the other.
    • Explain how capitalisation decides what a package exports.
    • Fix an undefined error caused by a lowercase name.
    • Lay out a module with several packages, and use internal/ to keep a package private to it.
    • Fix an "import cycle not allowed" error by moving the shared type into its own package.
    • Recognise the same HTTP route written with net/http, chi, gin, echo and fiber.
    • Compare a database query written with database/sql, sqlx, sqlc and GORM.
    • Find the entry point, routes and storage of an unfamiliar Go repo in a few minutes.

    Remember: Capitalisation is not style. It is the access modifier. You are not learning every framework. You are learning to recognise which one a codebase uses, and what that choice locked in.

Test yourself