Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find the Go module source cache?

I've upgraded a project to Go 1.11 and enabled module support for my project, but it seems that CircleCI is re-downloading the dependencies on every build. I know CircleCI allows caching between rebuilds, so I've looked at the documentation for Go modules, and while it mentions a cache, I can't seem to find where it actually exists.

Where is the source cache for Go modules?

like image 612
Rob G. Avatar asked Aug 29 '18 17:08

Rob G.


People also ask

Where is the go module cache?

Third-party modules are downloaded from their repositories into a module cache. These dependencies are then loaded from these copies when building applications. The module cache is by default located in the go subdirectory of the home directory.

Where are go modules stored Windows?

What is Go Module. A Module is a collection of Go packages stored in a file tree under $GOPATH/pkg folder with a go. mod file at its root.

Where do go modules get installed?

For this reason, make sure both your go. mod and go. sum files are checked into version control. All downloaded modules are cached locally in your $GOPATH/pkg/mod directory by default.

Where are go module dependencies installed?

Modules may be downloaded directly from version control repositories or from module proxy servers. A module is identified by a module path, which is declared in a go. mod file, together with information about the module's dependencies. The module root directory is the directory that contains the go.


1 Answers

As of the final 1.11 release, the go module cache (used for storing downloaded modules and source code), is in the $GOPATH/pkg/mod location (see the docs here). For clarification, the go build cache (used for storing recent compilation results) is in a different location.

This article, indicated that it's in the $GOPATH/src/mod, but in the timespan of the recent ~40 days, the golang team must have changed that target location. This message thread has some discussion on why the downloaded items ended up in $GOPATH/pkg.

You can also use the go mod download -json command to see the downloaded modules/source metadata and their location on your local disk. Example output below:

$ go mod download -json go: finding github.com/aws/aws-sdk-go v1.14.5 go: finding github.com/aws/aws-lambda-go v1.2.0 {     "Path": "github.com/aws/aws-lambda-go",     "Version": "v1.2.0",     "Info": "/go/pkg/mod/cache/download/github.com/aws/aws-lambda-go/@v/v1.2.0.info",     "GoMod": "/go/pkg/mod/cache/download/github.com/aws/aws-lambda-go/@v/v1.2.0.mod",     "Zip": "/go/pkg/mod/cache/download/github.com/aws/aws-lambda-go/@v/v1.2.0.zip",     "Dir": "/go/pkg/mod/github.com/aws/[email protected]",     "Sum": "h1:2f0pbAKMNNhvOkjI9BCrwoeIiduSTlYpD0iKEN1neuQ=",     "GoModSum": "h1:zUsUQhAUjYzR8AuduJPCfhBuKWUaDbQiPOG+ouzmE1A=" } {     "Path": "github.com/aws/aws-sdk-go",     "Version": "v1.14.5",     "Info": "/go/pkg/mod/cache/download/github.com/aws/aws-sdk-go/@v/v1.14.5.info",     "GoMod": "/go/pkg/mod/cache/download/github.com/aws/aws-sdk-go/@v/v1.14.5.mod",     "Zip": "/go/pkg/mod/cache/download/github.com/aws/aws-sdk-go/@v/v1.14.5.zip",     "Dir": "/go/pkg/mod/github.com/aws/[email protected]",     "Sum": "h1:+l1m6QH6LypE2kL0p/G0Oh7ceCv+IVQ1h5UEBt2xjjU=",     "GoModSum": "h1:ZRmQr0FajVIyZ4ZzBYKG5P3ZqPz9IHG41ZoMu1ADI3k=" } 

That output is from a build on CircleCI 2.0, using their official circleci/golang:1.11 image. This is a contrived example to show how you would include the restore_cache and save_cache steps for the new golang module cache location:

steps:     - checkout     - restore_cache:        keys:          - gomod-cache-{{ checksum "go.sum" }}     - run: go vet ./...     - save_cache:         key: gomod-cache-{{ checksum "go.sum" }}         paths:           - /go/pkg/mod 
like image 196
amcelwee Avatar answered Oct 24 '22 17:10

amcelwee