5

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

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
joaonrb
  • 965
  • 11
  • 30
  • You shouldn't ever have source files in the top level of "$GOPATH/src". Move your `main.go` into a package directory, and try `go run` from in there. – JimB Sep 16 '16 at 15:05
  • Thank you. This solves my problem. – joaonrb Sep 16 '16 at 15:38

1 Answers1

6

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.

Ainar-G
  • 34,563
  • 13
  • 93
  • 119
  • Did this and the error is pretty much the same. It try to find $GOPATH/src/github.com/valyala/fasthttp but the package is in $GOPATH/go-blog/vendor/github.com/valyala/fasthttp – joaonrb Sep 16 '16 at 15:32
  • @joaonrb It should be $GOPATH/**src**/go-blog/vendor/github.com/valyala/fasthttp See my edit. – Ainar-G Sep 16 '16 at 15:37