Reputation: 4471
I have private bitbucket
repo on http://localhost:7990
ππ» clone link http://localhost:7990/scm/gom/bar.git
go.mod
looks like:
module mod.org/bar
go 1.13
References available in a remote repository:
git ls-remote http://localhost:7990/scm/gom/bar.git
From http://localhost:7990/scm/gom/bar.git
d456de4f12785b26ac27ba08cffb76687d1287c8 HEAD
d456de4f12785b26ac27ba08cffb76687d1287c8 refs/heads/master
f948bd47a22c5fb9abed5bff468a10fc24f67483 refs/tags/v1.0.0
I changed .gitconfig
to
[url "http://localhost:7990/scm/gom"]
insteadOf = https://mod.org
and tried to get module by name
, get no such host
error:
go get -v mod.org/bar
go get lmod.org/bar: unrecognized import path "lmod.org/bar" (https fetch: Get https://lmod.org/bar?go-get=1: dial tcp: lookup lmod.org: no such host)
When I add extension .git
go get -v mod.org/bar.git
go: finding lmod.org/bar.git v1.0.0
go: downloading lmod.org/bar.git v1.0.0
verifying lmod.org/[email protected]: lmod.org/[email protected]: reading https://sum.golang.org/lookup/lmod.org/[email protected]: 410 Gone
go
download version with tag v1.0.0
to GOPATH = /Users/user/go"
:
$GOPATH
βββ go
βββ pkg
βββ mod
βββ cache
βββ download
βββ mod.org
βββ bar.git
βββ @v
βββ v1.0.0.info
βββ v1.0.0.lock
βββ v1.0.0.zip.tmp882433775
, but I still can't use one as dependency in other go-project.
Upvotes: 0
Views: 9659
Reputation: 4471
Steps to solve the problem:
1οΈβ£ changed module declaration in go.mod
to
module mod.org/gomod/bar
go 1.16
the same as bitbucket
repositories structure
repo's references to cloning:
http://localhost:7990/scm/gomod/bar.git
ssh://[email protected]/gomod/bar.git
2οΈβ£ change .gitconfig
: add insteadOf
(ssh
or https
)
# [url "http://localhost:7990/scm"]
[url "ssh://[email protected]"]
insteadOf = https://mod.org
3οΈβ£ add https://mod.org
to private repository
go env -w GOPRIVATE="mod.org"
βAfter all preparations the module will be accessible to go mod download
from other module by version tags
module mod.org/gomod/foo
go 1.16
require (
mod.org/gomod/bar v1.0.0-beta.1
)
replace (
mod.org/gomod/bar => mod.org/gomod/bar.git v1.0.0-beta.1
)
or manually
go get -u mod.org/gomod/bar.git
go get mod.org/gomod/[email protected]
Upvotes: 1
Reputation: 2532
You can't use private repo without .git
extension because of go tools don't know the version control protocol of your private repo, git or svn or any other.
For github.com
or golang.org
they are hardcoded into go's source.
The go tool will do a https
query to know that before fetching your private repo:
https://private/user/repo?go-get=1
If your private repo didn't support https
, please use replace
syntax of go module to tell go tools directly:
require private/user/repo v1.0.0
...
replace private/user/repo => private.server/user/repo.git v1.0.0
https://golang.org/cmd/go/#hdr-Remote_import_paths
Upvotes: 2
Reputation: 5187
The server for https://mod.org/bar
needs to return go-import
metadata following the protocol described in https://golang.org/cmd/go/#hdr-Remote_import_paths.
Several open-source implementations exist, such as:
You can store credentials (or access tokens) for both the HTTPS server and the underlying repository in a .netrc
file, and use the GOPRIVATE
environment variable to tell the go
command not to look for your private repo in the public proxy.
Upvotes: 3