liveBook · Manning

Go module

As explained in Learn Go with Pocket-Sized Projects

A Go module is a versioned collection of Go packages defined by a go.mod file.

A Go module is a project boundary initialized with go mod init and recorded in a go.mod file. Go code runs inside modules, whose names commonly match the repository path. section 2.1 section 8.1.2

Use a module as the starting point for different kinds of Go projects:

  • Create a fresh application directory, initialize its module, and add main.go with package main. section 2.1 section 3.1
  • Place a library package at the module root when you want users to import it with a short path. section 7.1.2
  • Keep a command-line tool's main.go at the module root when it exposes one binary; use cmd/{binary_name} for several binaries. section 6.1
  • Organize a simple CLI with main.go at the root and supporting code in an internal directory. section 9.2.1

Initialize a service module

Create a project directory and run `go mod init learngo/httpgordle`. After go.mod appears, add a main function, run the service with `go run .`, and test it at `http://localhost:8080`. section 8.1.2

> go mod init example.com/your-repository

Use the initialization command as the first executable step when starting a module; replace the example path with the chosen package or repository name. section 2.1

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Explains initialization, go.mod creation, naming, and common layouts, but does not detail dependency versioning or module commands beyond setup.
Examples
Uses hello-world, bookworms, genericcache, an HTTP service, a maze solver, and a money-conversion CLI.
What you can do after
Build it from scratch by initializing a module, creating go.mod, choosing a module path, and organizing application or library files.
How it connects
Connects modules with packages, go.mod, repository paths, main.go, internal directories, libraries, and command-line applications.

Also explained in

Compare how 4 books explain go module →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Go with Pocket-Sized Projects. The section links point to the parts of the book it draws on.