Start learning free

LESSON 147 OF 173 · BACKEND: SHIPPING IT

go.mod

Practice

On your computer, the shop builds with the modules you downloaded one day. A server starts with a fresh Go. It builds the shop from a file named go.mod: the module's name, the Go version, and one require line per module the shop needs, written path version.

Every version is exact and starts with v: go build uses that version on every machine, not whatever is newest on the day it runs. Packages that come with Go, like net/http and database/sql, stay out of the file: there is nothing to download. Here is the go.mod of another project, a small bot that sends a newsletter:

module newsletter
go 1.23
require github.com/robfig/cron/v3 v3.0.1

In this lesson the file's text is a Go raw string, goMod, between backticks. A raw string keeps every line break you type, so each line in the editor is one line of go.mod. The check reads the text the way go build would and prints:

go.mod:
module shop
go 1.23
require modernc.org/sqlite v1.34.5
go build:
module shop: names the module; go build and go run work inside it
go 1.23: the shop is built with Go 1.23 or newer, on every machine
modernc.org/sqlite v1.34.5: this exact version, on every machine
The shop needs a module name (go build works only inside a module): shop
The shop needs Go 1.22 or newer (routes like "GET /products/{id}" are new in Go 1.22): go 1.23
The shop needs modernc.org/sqlite (database/sql opens shop.db with it): pinned to v1.34.5

Your task: write the three lines of the shop's go.mod: the module's name, shop; the Go version 1.23 (the routes with {id} need Go 1.22 or newer); and modernc.org/sqlite at v1.34.5, the driver that opens shop.db.


Assignment
Follow the Coding Tutorial to write goMod, the text of the shop's go.mod, one line per part.


Hint
These lines are go.mod, not Go code: no quotes and no commas. Each line starts with module, go or require, and a require line's version starts with v.


STEP 1 OF 3
    Ctrl + Enter to check