Skip to content

Instantly share code, notes, and snippets.

@Integralist
Last active January 22, 2025 16:10
Show Gist options
  • Save Integralist/cf0bc36e17d8c28b04c6e7c5d5566e10 to your computer and use it in GitHub Desktop.
Save Integralist/cf0bc36e17d8c28b04c6e7c5d5566e10 to your computer and use it in GitHub Desktop.
[Golang go work] #go #golang #gowork

Create a new directory for your project.

Inside the directory git clone your projects.

Next, from within the project directory (where the individual projects are cloned within), create your go.work file.

You can do this in one of two ways:

go work init ./cli ./go-fastly

or

go work init 
go work use ./cli ./go-fastly

The latter is useful for changing the work file after you've started working.

You should end up with a file tree that looks something like this:

.
├── cli
│   ├── go.mod
├── go-fastly
│   ├── go.mod
├── go.work
├── go.work.sum

Now when you cd into one of the project directories (e.g. cd ./cli), and go run the code, you'll find it auto-magically identifies the dependency (e.g. ./go-fastly) and uses that instead of trying to pull the remote/real dependency.

Warning

This causes gopls in Neovim to report an error (although the LSP still works).
LSP[gopls]: Error SERVER_REQUEST_HANDLER_ERROR "... ENOENT: no such file or directory"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment