Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/vgo: always provide package name alongside import path #24361

josharian opened this issue Mar 12, 2018 · 1 comment


Copy link

commented Mar 12, 2018

This is going to be vague; apologies.

One source of frustration when working programmatically with imports is the need to use expensive go/build.Import calls to go from a package's import path to its name.

If you have a qualified identifier of interest, you need to build.Import the import path of every un-named import spec in the file (which is usually most of them) to find out whether the package name matches. This can have disproportionate cost.

This problem is particularly acute when you want to go from package name to import paths, as goimports does. You would need to read the entirety of the GOPATH to find matching packages. For performance reasons, goimports currently declines to do this and uses some heuristics around naming conventions to cut down on the number of candidate import paths. That's fine for goimports, but not for (say) guru.

vgo seems likely to be the future source of truth about all imports of interest in a project. It seems to me this might provide an opportunity for go.mod to provide a canonical mapping between package import paths and names, one that can be consumed with minimal I/O and filesystem interaction.

@rsc @alandonovan @keegancsmith @bradfitz

@josharian josharian added this to the vgo milestone Mar 12, 2018


This comment has been minimized.

Copy link

commented Mar 26, 2018

I don't think this can be done. vgo lists modules, each of which can have many packages. We don't want to force the go.mod file to list all the packages in the modules just to give their package names.

@rsc rsc closed this Mar 26, 2018

@golang golang locked and limited conversation to collaborators Mar 26, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
3 participants
You can’t perform that action at this time.