Search code examples
goosx-yosemitevendor

GO (Golang) vendor experiment failing on mac osx


Having some trouble getting the go vendor experiment working with go 1.6.2 on osx.

Heres my directory structure:

/project
    /application
        main.go
        other.go
        /vendor
            /github.com
                /vendor_name
                    /package_name

I have my GOPATH set to /Users/me/project/application However when I try to run any of the go tools (e.g build) it seems to be looking in application/src rather than application/vendor, getting lots of this:

main.go:15:2: cannot find package "github.com/facebookgo/grace/gracehttp" in any of:
    /usr/local/Cellar/go/1.6.2/libexec/src/github.com/facebookgo/grace/gracehttp (from $GOROOT)
    /Users/me/project/application/src/github.com/facebookgo/grace/gracehttp (from $GOPATH)

As you can see for go env output vendor experiment is on by default as it should be it just doesnt seem to work:

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/me/project/application"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.6.2/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.6.2/libexec/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT="1"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"

Now, the source of the funkiness may be a hangover from previous go installations. I had installed various versions of go over time, some through gvm (go version manager) and some through homebrew. So I have uninstalled gvm and the versions of go it had installed, also unstalled go with homebrew and reinstalled just 1.6.2 using homebrew.

go version output:

go version go1.6.2 darwin/amd64

which go:

/usr/local/bin/go

Any ideas what may have gone wrong here, or am I perhaps just misunderstanding how vendoring should work?

P.S. Please elt me know if you need more info, happy to provide


Solution

  • it seems to be looking in application/src

    Yes, go is looking in $GOPATH/src, both for your sources and for vendor sources folders.

    Everything should be in $GOPATH/src

    The vendor folder is meant to be importable only by code in the directory tree rooted at the parent of "vendor".
    But it is part of your sources, and as such, should be under $GOPATH/src.