How make go import packages from vendor?

joaonrb picture joaonrb · Sep 16, 2016 · Viewed 7.2k times · Source

I was checking the vendor feature in go with glide. It was awesome installing all packages but I couldn't manage to make go command to found them in the vendor packages.

go run src/main.go

src/main.go:8:2: cannot find package "github.com/valyala/fasthttp" in any of:
   /home/joaonrb/.software/lib/go/go1.7/src/github.com/valyala/fasthttp (from $GOROOT)
   /home/joaonrb/.projects/go-blog/src/github.com/valyala/fasthttp (from $GOPATH)

Fasthttp is installed in /home/joaonrb/.projects/go-blog/src/vendor/github.com/valyala/fasthttp, the version of go I'm using is 1.7 and my GOPATH is /home/joaonrb/.projects/go-blog

Answer

Ainar-G picture Ainar-G · Sep 16, 2016

Your GOPATH structure does not seem valid. To do what you want:

  • Create a "project" folder, e.g. $GOPATH/src/myproj.
  • Put your main.go there.
  • Create a vendor folder there, e.g. $GOPATH/src/myproj/vendor.
  • Put github.com/valyala/fasthttp there.

That should work.