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

cmd/go: need to have the command to view the current path of one package information #23082

Closed
wgliang opened this issue Dec 11, 2017 · 7 comments

Comments

@wgliang
Copy link
Contributor

wgliang commented Dec 11, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.9.2 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/wgliang/Documents"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.9.2/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.9.2/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/zd/20dl0mb523v4tjk_pf_hdscr0000gn/T/go-build387919256=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

I want to know the path of kubernetes I use where it is located by using the go which(or go path ...)github.com/kubernetes/kubernetes command. When my package is under more than one GOPATH or vendor, I do not know which package I use.

What did you expect to see?

Such as:
github.com/kubernetes/kubernetes:/Users/wgliang/Documents/src/github.com/kubernetes/kubernetes

What did you see instead?

No this function. And I wish to have this command.

@wgliang wgliang changed the title cmd / go: need to have the command to view the current version of the package information cmd/go: need to have the command to view the current version of the package information Dec 11, 2017
@wgliang wgliang changed the title cmd/go: need to have the command to view the current version of the package information cmd/go: need to have the command to view the current path of one package information Dec 11, 2017
@mvdan
Copy link
Member

mvdan commented Dec 11, 2017

You mean this command?

$ go list -f '{{.Dir}}' golang.org/x/tools/cmd/goimports
/home/mvdan/go/src/golang.org/x/tools/cmd/goimports

@wgliang
Copy link
Contributor Author

wgliang commented Dec 11, 2017

Yes,but I got:

$ pwd
/Users/wgliang/Documents/mos/src/github.com/kubernetes/kubernetes
$ go list -f '{{.Dir}}' github.com/kubernetes/kubernetes
can't load package: package github.com/kubernetes/kubernetes: no Go files in /Users/wgliang/Documents/mos/src/github.com/kubernetes/kubernetes

This can not solve my problem.I need to know which package I am using in the current directory or what the priority list is.

@mvdan
Copy link
Member

mvdan commented Dec 11, 2017

Because that is not a Go package - it has no Go files.

@wgliang
Copy link
Contributor Author

wgliang commented Dec 11, 2017

Yeah,I know it. But I think we can add such a feature, so that we can more clearly when we want to import a package.

@mvdan
Copy link
Member

mvdan commented Dec 11, 2017

I think there's some level of confusion here. A directory under $GOPATH/src is not automatically a Go package, as far as I know - it requires at least one Go file in it that isn't hidden. Note that the file doesn't have to be buildable for go list to work.

So, if you're asking for a command to print the directory where a Go package is, you want go list -f '{{.Dir}}'.

If you also want it to work for directories that have no Go files at all, I'm not sure what to answer. I cannot find any documentation explicitly mentioning it, but all tools seem to require at least one Go file in a directory for it to be a Go package. It sounds to me like you should rephrase your feature request to not mention "packages", unless you want to change the definition of what a package is too.

@bradfitz
Copy link
Contributor

@wgliang, are you looking for the same thing as #18119 ?

@wgliang
Copy link
Contributor Author

wgliang commented Dec 14, 2017

@bradfitz Yes, your idea coincides with mine.

I will close this issue.

@wgliang wgliang closed this as completed Dec 14, 2017
@golang golang locked and limited conversation to collaborators Dec 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants