Powerful Command-Line Applications in Go: module initialization info wrong (Preface page xxiv)

The book states “Upon initializing a new module, Go creates a file go.mod in the root of your
module directory” but, at least in Go 1.20, that is not true. It is created in the current working directory.

$ go help mod init
usage: go mod init [module-path]

Init initializes and writes a new go.mod file in the current directory, in
effect creating a new module rooted at the current directory. The go.mod file
must not already exist.

This means that the example of creating a nested directory, initializing it and then showing the contexts of the go.mod work, but the wrong directory has been initialized with the new go.mod file.

1 Like

Hello @outofphase . Thank you for your comment. You’re right and the text is missing the direction to switch into the newly created directory before initializing the module.

cd  $HOME/pragprog.com/rggo/firstProgram/wc

I’ll update it for the next version.

Thanks,
Ricardo