Description
When executing the command go list -m -u -json all
having the root repository path and sub-module directory information would be useful in determining where exactly a module came from.
This would help determining where it was downloaded from and what tag was used to get the correct version of the module to debug any issues related to the module.
In the go module documentation there is the following example:
<meta name="go-import" content="golang.org/x/mod git https://go.googlesource.com/mod"
If the module imports golang.org/x/mod you would think that it is downloading the module from https://golang.org
exactly.
Based on the result of the go-get query in the example, the repository where the module is downloaded from is https://go.googlesource.com/mod
This illustrates that the repository URL could be different.
Since go already calculates the repository root path and the submodule directory to obtain modules internally within go, I am proposing two additional fields to be added to the module data.
"RepositoryRootPath": "",
"ModuleSubdirectory": ""
Always show the RepositoryRootPath for all modules when listing them.
If the module is located in a subdirectory of the root repository, then add the ModuleSubdirectory to the output of the module.
What version of Go are you using (go version
)?
$ go version go version go1.15.5 darwin/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GO111MODULE="on" GOARCH="amd64" GOBIN="" GOCACHE="/Users/user-1/Library/Caches/go-build" GOENV="/Users/user-1/Library/Application Support/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOINSECURE="" GOMODCACHE="/Users/user-1/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="darwin" GOPATH="/Users/user-1/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64" GCCGO="gccgo" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="/Users/user-1/go/azure-autorest-test/src/go.mod" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/s7/pngnf4m90m3gxp02xxpm5wkh0000gn/T/go-build227528808=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
I created a sample module that imports modules that are in a subdirectory of a root repository.
main.go
package main
import (
"fmt"
"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/Azure/go-autorest/autorest/validation"
"github.com/Azure/go-autorest/autorest/to"
)
func main() {
fmt.Println("Hello repository with subdirectory modules test!");
}
go.mod
module example.com/submodule-test
go 1.15
require (
github.com/Azure/go-autorest/autorest v0.11.11
github.com/Azure/go-autorest/autorest/to v0.4.0
github.com/Azure/go-autorest/autorest/validation v0.3.0
)
What did you expect to see?
go list -m -u -json all
Output:
{ "Path": "example.com/submodule-test", "Main": true, "Dir": "/Users/user-1/go/submodule-test/src", "GoMod": "/Users/user-1/go/submodule-test/src/go.mod", "GoVersion": "1.15" } { "Path": "github.com/Azure/go-autorest", "RepositoryRootPath": "github.com/Azure/go-autorest", "Version": "v14.2.0+incompatible", "Time": "2020-06-23T16:10:07Z", "Indirect": true, "Dir": "/Users/user-1/go/pkg/mod/github.com/!azure/go-autorest@v14.2.0+incompatible", "GoMod": "/Users/user-1/go/pkg/mod/cache/download/github.com/!azure/go-autorest/@v/v14.2.0+incompatible.mod" } { "Path": "github.com/Azure/go-autorest/autorest", "RepositoryRootPath": "github.com/Azure/go-autorest", "ModuleSubdirectory": "autorest", "Version": "v0.11.11", "Time": "2020-11-09T22:22:39Z", "Dir": "/Users/user-1/go/pkg/mod/github.com/!azure/go-autorest/autorest@v0.11.11", "GoMod": "/Users/user-1/go/pkg/mod/cache/download/github.com/!azure/go-autorest/autorest/@v/v0.11.11.mod", "GoVersion": "1.12" } { "Path": "github.com/Azure/go-autorest/autorest/adal", "RepositoryRootPath": "github.com/Azure/go-autorest", "ModuleSubdirectory": "autorest/adal", "Version": "v0.9.5", "Time": "2020-10-06T19:19:20Z", "Indirect": true, "Dir": "/Users/user-1/go/pkg/mod/github.com/!azure/go-autorest/autorest/adal@v0.9.5", "GoMod": "/Users/user-1/go/pkg/mod/cache/download/github.com/!azure/go-autorest/autorest/adal/@v/v0.9.5.mod", "GoVersion": "1.12" } { "Path": "github.com/Azure/go-autorest/autorest/date", "RepositoryRootPath": "github.com/Azure/go-autorest", "ModuleSubdirectory": "autorest/date", "Version": "v0.3.0", "Time": "2020-06-23T18:36:26Z", "Indirect": true, "Dir": "/Users/user-1/go/pkg/mod/github.com/!azure/go-autorest/autorest/date@v0.3.0", "GoMod": "/Users/user-1/go/pkg/mod/cache/download/github.com/!azure/go-autorest/autorest/date/@v/v0.3.0.mod", "GoVersion": "1.12" } { "Path": "github.com/Azure/go-autorest/autorest/mocks", "RepositoryRootPath": "github.com/Azure/go-autorest", "ModuleSubdirectory": "autorest/mocks", "Version": "v0.4.1", "Time": "2020-08-13T18:36:39Z", "Indirect": true, "Dir": "/Users/user-1/go/pkg/mod/github.com/!azure/go-autorest/autorest/mocks@v0.4.1", "GoMod": "/Users/user-1/go/pkg/mod/cache/download/github.com/!azure/go-autorest/autorest/mocks/@v/v0.4.1.mod", "GoVersion": "1.12" } { "Path": "github.com/Azure/go-autorest/autorest/to", "RepositoryRootPath": "github.com/Azure/go-autorest", "ModuleSubdirectory": "autorest/to", "Version": "v0.4.0", "Time": "2020-06-23T18:36:26Z", "Dir": "/Users/user-1/go/pkg/mod/github.com/!azure/go-autorest/autorest/to@v0.4.0", "GoMod": "/Users/user-1/go/pkg/mod/cache/download/github.com/!azure/go-autorest/autorest/to/@v/v0.4.0.mod", "GoVersion": "1.12" } { "Path": "github.com/Azure/go-autorest/autorest/validation", "RepositoryRootPath": "github.com/Azure/go-autorest", "ModuleSubdirectory": "autorest/validation", "Version": "v0.3.0", "Time": "2020-06-23T18:36:26Z", "Dir": "/Users/user-1/go/pkg/mod/github.com/!azure/go-autorest/autorest/validation@v0.3.0", "GoMod": "/Users/user-1/go/pkg/mod/cache/download/github.com/!azure/go-autorest/autorest/validation/@v/v0.3.0.mod", "GoVersion": "1.12" } { "Path": "github.com/Azure/go-autorest/logger", "RepositoryRootPath": "github.com/Azure/go-autorest", "ModuleSubdirectory": "logger", "Version": "v0.2.0", "Time": "2020-06-23T18:36:26Z", "Indirect": true, "Dir": "/Users/user-1/go/pkg/mod/github.com/!azure/go-autorest/logger@v0.2.0", "GoMod": "/Users/user-1/go/pkg/mod/cache/download/github.com/!azure/go-autorest/logger/@v/v0.2.0.mod", "GoVersion": "1.12" } { "Path": "github.com/Azure/go-autorest/tracing", "RepositoryRootPath": "github.com/Azure/go-autorest", "ModuleSubdirectory": "tracing", "Version": "v0.6.0", "Time": "2020-06-23T18:36:26Z", "Indirect": true, "Dir": "/Users/user-1/go/pkg/mod/github.com/!azure/go-autorest/tracing@v0.6.0", "GoMod": "/Users/user-1/go/pkg/mod/cache/download/github.com/!azure/go-autorest/tracing/@v/v0.6.0.mod", "GoVersion": "1.12" } { "Path": "github.com/davecgh/go-spew", "RepositoryRootPath": "github.com/davecgh/go-spew", "Version": "v1.1.0", "Time": "2016-10-29T20:57:26Z", "Update": { "Path": "github.com/davecgh/go-spew", "Version": "v1.1.1", "Time": "2018-02-21T23:26:28Z" }, "Indirect": true, "Dir": "/Users/user-1/go/pkg/mod/github.com/davecgh/go-spew@v1.1.0", "GoMod": "/Users/user-1/go/pkg/mod/cache/download/github.com/davecgh/go-spew/@v/v1.1.0.mod" } { "Path": "github.com/form3tech-oss/jwt-go", "RepositoryRootPath": "github.com/form3tech-oss/jwt-go", "Version": "v3.2.2+incompatible", "Time": "2020-09-15T13:53:29Z", "Indirect": true, "Dir": "/Users/user-1/go/pkg/mod/github.com/form3tech-oss/jwt-go@v3.2.2+incompatible", "GoMod": "/Users/user-1/go/pkg/mod/cache/download/github.com/form3tech-oss/jwt-go/@v/v3.2.2+incompatible.mod" } { "Path": "github.com/pmezard/go-difflib", "RepositoryRootPath": "github.com/pmezard/go-difflib", "Version": "v1.0.0", "Time": "2016-01-10T10:55:54Z", "Indirect": true, "Dir": "/Users/user-1/go/pkg/mod/github.com/pmezard/go-difflib@v1.0.0", "GoMod": "/Users/user-1/go/pkg/mod/cache/download/github.com/pmezard/go-difflib/@v/v1.0.0.mod" } { "Path": "github.com/stretchr/objx", "RepositoryRootPath": "github.com/stretchr/objx", "Version": "v0.1.0", "Time": "2018-01-06T01:13:53Z", "Update": { "Path": "github.com/stretchr/objx", "Version": "v0.3.0", "Time": "2019-04-15T11:18:23Z" }, "Indirect": true, "GoMod": "/Users/user-1/go/pkg/mod/cache/download/github.com/stretchr/objx/@v/v0.1.0.mod" } { "Path": "github.com/stretchr/testify", "RepositoryRootPath": "github.com/stretchr/testify", "Version": "v1.3.0", "Time": "2019-01-03T19:31:39Z", "Update": { "Path": "github.com/stretchr/testify", "Version": "v1.6.1", "Time": "2020-06-05T10:48:45Z" }, "Indirect": true, "Dir": "/Users/user-1/go/pkg/mod/github.com/stretchr/testify@v1.3.0", "GoMod": "/Users/user-1/go/pkg/mod/cache/download/github.com/stretchr/testify/@v/v1.3.0.mod" } { "Path": "golang.org/x/crypto", "RepositoryRootPath": "go.googlesource.com/crypto", "Version": "v0.0.0-20201002170205-7f63de1d35b0", "Time": "2020-10-02T17:02:05Z", "Update": { "Path": "golang.org/x/crypto", "Version": "v0.0.0-20201117144127-c1f2f97bffc9", "Time": "2020-11-17T14:41:27Z" }, "Indirect": true, "Dir": "/Users/user-1/go/pkg/mod/golang.org/x/crypto@v0.0.0-20201002170205-7f63de1d35b0", "GoMod": "/Users/user-1/go/pkg/mod/cache/download/golang.org/x/crypto/@v/v0.0.0-20201002170205-7f63de1d35b0.mod", "GoVersion": "1.11" } { "Path": "golang.org/x/net", "RepositoryRootPath": "go.googlesource.com/net", "Version": "v0.0.0-20190404232315-eb5bcb51f2a3", "Time": "2019-04-04T23:23:15Z", "Update": { "Path": "golang.org/x/net", "Version": "v0.0.0-20201110031124-69a78807bb2b", "Time": "2020-11-10T03:11:24Z" }, "Indirect": true, "GoMod": "/Users/user-1/go/pkg/mod/cache/download/golang.org/x/net/@v/v0.0.0-20190404232315-eb5bcb51f2a3.mod" } { "Path": "golang.org/x/sys", "RepositoryRootPath": "go.googlesource.com/sys", "Version": "v0.0.0-20190412213103-97732733099d", "Time": "2019-04-12T21:31:03Z", "Update": { "Path": "golang.org/x/sys", "Version": "v0.0.0-20201119102817-f84b799fce68", "Time": "2020-11-19T10:28:17Z" }, "Indirect": true, "GoMod": "/Users/user-1/go/pkg/mod/cache/download/golang.org/x/sys/@v/v0.0.0-20190412213103-97732733099d.mod", "GoVersion": "1.12" } { "Path": "golang.org/x/text", "RepositoryRootPath": "go.googlesource.com/text", "Version": "v0.3.0", "Time": "2017-12-14T13:08:43Z", "Update": { "Path": "golang.org/x/text", "Version": "v0.3.4", "Time": "2020-10-21T14:53:29Z" }, "Indirect": true, "GoMod": "/Users/user-1/go/pkg/mod/cache/download/golang.org/x/text/@v/v0.3.0.mod" }
What did you see instead?
go list -m -u -json all
go list -m -u -json all
Output
{ "Path": "example.com/azure-test", "Main": true, "Dir": "/Users/user-1/go/azure-autorest-test/src", "GoMod": "/Users/user-1/go/azure-autorest-test/src/go.mod", "GoVersion": "1.15" } { "Path": "github.com/Azure/go-autorest", "Version": "v14.2.0+incompatible", "Time": "2020-06-23T16:10:07Z", "Indirect": true, "Dir": "/Users/user-1/go/pkg/mod/github.com/!azure/go-autorest@v14.2.0+incompatible", "GoMod": "/Users/user-1/go/pkg/mod/cache/download/github.com/!azure/go-autorest/@v/v14.2.0+incompatible.mod" } { "Path": "github.com/Azure/go-autorest/autorest", "Version": "v0.11.11", "Time": "2020-11-09T22:22:39Z", "Dir": "/Users/user-1/go/pkg/mod/github.com/!azure/go-autorest/autorest@v0.11.11", "GoMod": "/Users/user-1/go/pkg/mod/cache/download/github.com/!azure/go-autorest/autorest/@v/v0.11.11.mod", "GoVersion": "1.12" } { "Path": "github.com/Azure/go-autorest/autorest/adal", "Version": "v0.9.5", "Time": "2020-10-06T19:19:20Z", "Indirect": true, "Dir": "/Users/user-1/go/pkg/mod/github.com/!azure/go-autorest/autorest/adal@v0.9.5", "GoMod": "/Users/user-1/go/pkg/mod/cache/download/github.com/!azure/go-autorest/autorest/adal/@v/v0.9.5.mod", "GoVersion": "1.12" } { "Path": "github.com/Azure/go-autorest/autorest/date", "Version": "v0.3.0", "Time": "2020-06-23T18:36:26Z", "Indirect": true, "Dir": "/Users/user-1/go/pkg/mod/github.com/!azure/go-autorest/autorest/date@v0.3.0", "GoMod": "/Users/user-1/go/pkg/mod/cache/download/github.com/!azure/go-autorest/autorest/date/@v/v0.3.0.mod", "GoVersion": "1.12" } { "Path": "github.com/Azure/go-autorest/autorest/mocks", "Version": "v0.4.1", "Time": "2020-08-13T18:36:39Z", "Indirect": true, "Dir": "/Users/user-1/go/pkg/mod/github.com/!azure/go-autorest/autorest/mocks@v0.4.1", "GoMod": "/Users/user-1/go/pkg/mod/cache/download/github.com/!azure/go-autorest/autorest/mocks/@v/v0.4.1.mod", "GoVersion": "1.12" } { "Path": "github.com/Azure/go-autorest/autorest/to", "Version": "v0.4.0", "Time": "2020-06-23T18:36:26Z", "Dir": "/Users/user-1/go/pkg/mod/github.com/!azure/go-autorest/autorest/to@v0.4.0", "GoMod": "/Users/user-1/go/pkg/mod/cache/download/github.com/!azure/go-autorest/autorest/to/@v/v0.4.0.mod", "GoVersion": "1.12" } { "Path": "github.com/Azure/go-autorest/autorest/validation", "Version": "v0.3.0", "Time": "2020-06-23T18:36:26Z", "Dir": "/Users/user-1/go/pkg/mod/github.com/!azure/go-autorest/autorest/validation@v0.3.0", "GoMod": "/Users/user-1/go/pkg/mod/cache/download/github.com/!azure/go-autorest/autorest/validation/@v/v0.3.0.mod", "GoVersion": "1.12" } { "Path": "github.com/Azure/go-autorest/logger", "Version": "v0.2.0", "Time": "2020-06-23T18:36:26Z", "Indirect": true, "Dir": "/Users/user-1/go/pkg/mod/github.com/!azure/go-autorest/logger@v0.2.0", "GoMod": "/Users/user-1/go/pkg/mod/cache/download/github.com/!azure/go-autorest/logger/@v/v0.2.0.mod", "GoVersion": "1.12" } { "Path": "github.com/Azure/go-autorest/tracing", "Version": "v0.6.0", "Time": "2020-06-23T18:36:26Z", "Indirect": true, "Dir": "/Users/user-1/go/pkg/mod/github.com/!azure/go-autorest/tracing@v0.6.0", "GoMod": "/Users/user-1/go/pkg/mod/cache/download/github.com/!azure/go-autorest/tracing/@v/v0.6.0.mod", "GoVersion": "1.12" } { "Path": "github.com/davecgh/go-spew", "Version": "v1.1.0", "Time": "2016-10-29T20:57:26Z", "Update": { "Path": "github.com/davecgh/go-spew", "Version": "v1.1.1", "Time": "2018-02-21T23:26:28Z" }, "Indirect": true, "Dir": "/Users/user-1/go/pkg/mod/github.com/davecgh/go-spew@v1.1.0", "GoMod": "/Users/user-1/go/pkg/mod/cache/download/github.com/davecgh/go-spew/@v/v1.1.0.mod" } { "Path": "github.com/form3tech-oss/jwt-go", "Version": "v3.2.2+incompatible", "Time": "2020-09-15T13:53:29Z", "Indirect": true, "Dir": "/Users/user-1/go/pkg/mod/github.com/form3tech-oss/jwt-go@v3.2.2+incompatible", "GoMod": "/Users/user-1/go/pkg/mod/cache/download/github.com/form3tech-oss/jwt-go/@v/v3.2.2+incompatible.mod" } { "Path": "github.com/pmezard/go-difflib", "Version": "v1.0.0", "Time": "2016-01-10T10:55:54Z", "Indirect": true, "Dir": "/Users/user-1/go/pkg/mod/github.com/pmezard/go-difflib@v1.0.0", "GoMod": "/Users/user-1/go/pkg/mod/cache/download/github.com/pmezard/go-difflib/@v/v1.0.0.mod" } { "Path": "github.com/stretchr/objx", "Version": "v0.1.0", "Time": "2018-01-06T01:13:53Z", "Update": { "Path": "github.com/stretchr/objx", "Version": "v0.3.0", "Time": "2019-04-15T11:18:23Z" }, "Indirect": true, "GoMod": "/Users/user-1/go/pkg/mod/cache/download/github.com/stretchr/objx/@v/v0.1.0.mod" } { "Path": "github.com/stretchr/testify", "Version": "v1.3.0", "Time": "2019-01-03T19:31:39Z", "Update": { "Path": "github.com/stretchr/testify", "Version": "v1.6.1", "Time": "2020-06-05T10:48:45Z" }, "Indirect": true, "Dir": "/Users/user-1/go/pkg/mod/github.com/stretchr/testify@v1.3.0", "GoMod": "/Users/user-1/go/pkg/mod/cache/download/github.com/stretchr/testify/@v/v1.3.0.mod" } { "Path": "golang.org/x/crypto", "Version": "v0.0.0-20201002170205-7f63de1d35b0", "Time": "2020-10-02T17:02:05Z", "Update": { "Path": "golang.org/x/crypto", "Version": "v0.0.0-20201117144127-c1f2f97bffc9", "Time": "2020-11-17T14:41:27Z" }, "Indirect": true, "Dir": "/Users/user-1/go/pkg/mod/golang.org/x/crypto@v0.0.0-20201002170205-7f63de1d35b0", "GoMod": "/Users/user-1/go/pkg/mod/cache/download/golang.org/x/crypto/@v/v0.0.0-20201002170205-7f63de1d35b0.mod", "GoVersion": "1.11" } { "Path": "golang.org/x/net", "Version": "v0.0.0-20190404232315-eb5bcb51f2a3", "Time": "2019-04-04T23:23:15Z", "Update": { "Path": "golang.org/x/net", "Version": "v0.0.0-20201110031124-69a78807bb2b", "Time": "2020-11-10T03:11:24Z" }, "Indirect": true, "GoMod": "/Users/user-1/go/pkg/mod/cache/download/golang.org/x/net/@v/v0.0.0-20190404232315-eb5bcb51f2a3.mod" } { "Path": "golang.org/x/sys", "Version": "v0.0.0-20190412213103-97732733099d", "Time": "2019-04-12T21:31:03Z", "Update": { "Path": "golang.org/x/sys", "Version": "v0.0.0-20201119102817-f84b799fce68", "Time": "2020-11-19T10:28:17Z" }, "Indirect": true, "GoMod": "/Users/user-1/go/pkg/mod/cache/download/golang.org/x/sys/@v/v0.0.0-20190412213103-97732733099d.mod", "GoVersion": "1.12" } { "Path": "golang.org/x/text", "Version": "v0.3.0", "Time": "2017-12-14T13:08:43Z", "Update": { "Path": "golang.org/x/text", "Version": "v0.3.4", "Time": "2020-10-21T14:53:29Z" }, "Indirect": true, "GoMod": "/Users/user-1/go/pkg/mod/cache/download/golang.org/x/text/@v/v0.3.0.mod" }