Home > Article > Backend Development > How to support multiple go mod modules in a single repository
I am writing Go recently. There is a project with multiple modules. The versions are released together. In order to use these modules for other projects, it is necessary Implement the release of multiple modules in one warehouse.
The warehouse structure is as follows:
.├── README.md ├── a │ ├── a.go │ └── go.mod └── b ├── b.go └── go.mod
a/go.mod
is generated using the following command:
go mod init github.com/robberphex/go-test-multi-module/a
Because it is multi-module, different tags are used. The tag names are uniformly <module name>/<version number>
.
For example, the current tags are:
$ git tag a/v1.0.0 b/v1.0.0 b/v1.0.1
When installing, users only need to execute the same command as a normal module:
$ go get github.com/robberphex/go-test-multi-module/b go: downloading github.com/robberphex/go-test-multi-module/b v1.0.1 go: downloading github.com/robberphex/go-test-multi-module v0.0.0-20210420014022-d2c7262e89eb $ go get github.com/robberphex/go-test-multi-module/a go: downloading github.com/robberphex/go-test-multi-module/a v1.0.0
However, in the case of multiple modules, if you use VSCode to open the warehouse (root directory), VSCode will report an error, involving the automatic complement of third-party packages. None of them work:
I checked the information according to the prompts and found that golps only supports multi-module warehouses experimentally and needs to be manually Turn on this switch:
"gopls": { "build.experimentalWorkspaceModule": true}
This way you can develop multi-module projects smoothly.
P.S. There is also a switch ui.completion.experimentalPostfixCompletions
that is also very useful. You can turn it on and see. The effect is as follows:
For more golang related technical articles, please visit the golang tutorial column!
The above is the detailed content of How to support multiple go mod modules in a single repository. For more information, please follow other related articles on the PHP Chinese website!