go mod init creates a go.mod file in the current directory and starts a Go module. This lets a project build outside GOPATH while giving its packages a shared import-path prefix and a foundation for versioned dependencies. section 2.3.2 section 11.1
Choose the module path carefully because it:
- Identifies the module uniquely. section 11.1
- Becomes the import-path prefix for packages inside the module. section 11.1
- Should match the repository location for hosted modules, with subdirectories for multimodule repositories and /v2-style suffixes for major versions. section 11.1
Initialize a wordcount module
Run `go mod init gobook/wordcount` from the project directory. Go creates a minimal go.mod containing `module gobook/wordcount` and a Go language version. As dependencies are added, go.mod records their versions; go.sum records cryptographic checksums used for reproducible, tamper-resistant builds. section 2.3.2 section 11.1
Listing 2.1 Initializing the wordcount module
$ go mod init gobook/wordcount go: creating new go.mod: module gobook/wordcount
Inspect the command output for a concrete module initialization. section 2.3.2

