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
To import a package, we use import syntax followed by the package name. 💡 Unlike other programming languages, a package name can also be a subpath like some-dir/greet and Go will automatically resolve the path to the greet package for us as you will see in the nested package topic ahead.
The go mod vendor command constructs a directory named vendor in the main module's root directory that contains copies of all packages needed to support builds and tests of packages in the main module. Packages that are only imported by tests of packages outside the main module are not included.
2. Grouped import. Go also supports grouped imports. This means that you don't have to write the import keyword multiple times; instead, you can use the keyword import followed by round braces, (), and mention all the packages inside the round braces that you wish to import.
What is Go Module. A Module is a collection of Go packages stored in a file tree under $GOPATH/pkg folder with a go. mod file at its root.
Your GOPATH structure does not seem valid. To do what you want:
$GOPATH/src/myproj
.$GOPATH/src/myproj/vendor
.github.com/valyala/fasthttp
there.That should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With