I have a go package located on my filesystem (not in the $GOPATH
), called bitbucket.org/me/awesome
.
~/awesome> tree
.
├── main.go
├── go.mod
├── go.sum
├── subpackageA
│ └── main.go
My go.mod
looks like:
module bitbucket.org/me/awesome
require (
... # lots of external dependencies
)
replace bitbucket.org/me/awesome => ./
In main.go
in my top-level directory, I call a subpackage like follows:
import "bitbucket.org/me/awesome/subpackageA"
which all seems pretty normal. go get
works. However, when I clone this entire repository somewhere else (say in a Docker image) and run go get
for the first time, I get errors like:
package bitbucket.org/me/awesome/subpackageA: https://api.bitbucket.org/2.0/repositories/me/awesome?fields=scm: 403 Forbidden
,
which means it's not using the local filesystem version of the packages, even though I told it to with the replace
directive in the go.mod
file.
What am I doing wrong? How do I ensure that subpackages are used from the filesystem instead of attempting to be fetched from the internet?
replace
lines for subpackages). Do you want to add your comment as an answer? – Giaourbitbucket.org/me/awesome
module, and packages within the same module should find each other automatically without needing areplace
directive. – Aeonreplace
directives only operate on modules as the left-side and right-side arguments, and not on subpackages or packages, unless a package is in the root of the module, in which case the package path and module path are the same, but even then thereplace
directive is really operating at the module level). – Aeon