Hello everyone. I’m currently learning Go and there is one question that I want to ask:
I’ve read that use of GOPATH is deprecated since 1.11 because of modules but whenever I download libraries with go get or go install, its getting put inside GOPATH/pkg directory.
Is that default/correct behavior? Can I force it to store libraries inside the module from which I’m calling go get/install command? Or is it a bad practice ?
The GOPATH is deprecated as the “workspace” mechanism to host your projects.
It is still used though to install binaries (bin) to or ready to link artifacts from external libraries (pkg).
All that @NobbZ wrote applies, plus:
I guess you refer to vendoring. Yes, this can be done.
go mod vendor downloads all dependencies of the current module into a “vendor” folder.
See Go Modules Reference - The Go Programming Language for details.