Skip to content

Instantly share code, notes, and snippets.

@matej-g
Last active January 25, 2023 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matej-g/1bbcb2ac1becf6cfebc8f146d6a069c1 to your computer and use it in GitHub Desktop.
Save matej-g/1bbcb2ac1becf6cfebc8f146d6a069c1 to your computer and use it in GitHub Desktop.
Generate `go.work` file automatically with this two-liner

Go workspaces is a feature available from 1.18 (https://go.dev/doc/tutorial/workspaces).

If you work with repositories that have numerous nested Go modules, it can be annoying having to add each with a go work use command. You can run this two-liner from the base of the repository to initiate and create your go.work automatically, including all nested Go modules:

go work init
go work use $(find . -type f -name 'go.mod' -exec dirname {} \; | sort)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment