Skip to content

cmd/go: issues with shared $GOPATH/pkg/mod cache and autogenerated modules #32235

Closed
@sirkon

Description

@sirkon

Hi!

At my job we have a single repository with proto-files grouped by directories. Something like gitlab.example.com/common/schema/<service path>/<file.proto>

We were generating this into $GOPATH/src/gen/<service path>/<file.go> and import this as gen/<service path>

Now we did a server which acts like a good go modules proxy except the case when it is requested for gitlab.example.com/common/schema/<service path>/v34. It generates go code from gitlab.example.com/common/schema/<service path>/*.proto files and return them as regular go module. Sounds nice and it works great in most cases except one thing: most our projects use code generated with protoc-gen-go, but some are playing with code generated by protoc-gen-gofast.

Our decision was to have two URL serving goproxies: https://goproxy.example.com/go and https://goproxy.example.com/gofast where the first one requests for 3rd party goproxies and returns code generated with protoc-gen-go and the other one works exactly the same except it would return code generated with protoc-gen-gofast. We thought we would simply use different GOPROXY for different projects and everything will be great.

And this doesn't work that easy unfortunately: we have shared $GOPATH/pkg/mod – cache directory for downloaded modules. And we will have exactly the same autogenerated module of certain version for project A if we have already requested this version of the module for project B despite having different sources.

Sure, we can manually clean cache dir but this is … ugly. We would probably have different cache directories with different GOPATH, but we would prefer to keep it the same.

So I have a proposal: a new environment variable called GOCACHE or GOMODCACHE or whatever to control modules cache. This would ease the development if editor/IDE supports project profiles.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.modules

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions