我正在寻找获得$ go与私人存储库工作的方法,经过许多谷歌尝试。

第一次尝试:

$ go get -v gitlab.com/secmask/awserver-go
Fetching https://gitlab.com/secmask/awserver-go?go-get=1
https fetch failed.
Fetching http://gitlab.com/secmask/awserver-go?go-get=1
Parsing meta tags from http://gitlab.com/secmask/awserver-go?go-get=1 (status code 200)
import "gitlab.com/secmask/awserver-go": parse http://gitlab.com/secmask/awserver-go?go-get=1: no go-import meta tags
package gitlab.com/secmask/awserver-go: unrecognized import path "gitlab.com/secmask/awserver-go

是的,它没有看到元标签,因为我不知道如何提供登录信息。

第二次尝试:

按照https://gist.github.com/shurcooL/6927554。将config添加到.gitconfig。

[url "ssh://git@gitlab.com/"]
    insteadOf = https://gitlab.com/
$ go get -v gitlab.com/secmask/awserver-go --> not work
$ go get -v gitlab.com/secmask/awserver-go.git --> work but I got src/gitlab.com/secmask/awserer-go.git

是的,它的工作,但与。git扩展与我的项目名称,我可以重命名为原来的,但每次做$ go get不太好,有没有其他方法?


当前回答

确保你删除了你之前的gitconfig,我也有同样的问题。

之前我执行了令牌过期的gitconfig,当你下次使用新令牌执行命令时,一定要删除之前的令牌。

其他回答

确保你删除了你之前的gitconfig,我也有同样的问题。

之前我执行了令牌过期的gitconfig,当你下次使用新令牌执行命令时,一定要删除之前的令牌。

对于独立/最终回购,作为快速修复,为什么不直接在go中命名模块呢?Mod作为一个包使用贵公司的域名…?

module go.yourcompany.tld/the_repo

Go.yourcompany.tld甚至不必作为有效(子)域名存在…

同样,在同一个地方。mod你可以使用替换块/行来使用之前以同样的方式克隆的私有回购(在$GOPATH/src/go.yourcompany.tld中克隆的各自文件夹中)(为什么我们必须在GitHub中依赖太多?)

Edit

不用说,私人回购通常应该是私人回购,通常是标准的git回购,对吧?有了这些,为什么不直接克隆git,然后进入克隆文件夹?

这是Go Get中的硬代码。不是Git的原因。修改Go Source。 原因: reportforimportdynamic将请求:https://....go-get

// RepoRootForImportPath analyzes importPath to determine the
// version control system, and code repository to use.
func RepoRootForImportPath(importPath string, mod ModuleMode, security web.SecurityMode) (*RepoRoot, error) {
    rr, err := repoRootFromVCSPaths(importPath, security, vcsPaths)
    if err == errUnknownSite {
        rr, err = repoRootForImportDynamic(importPath, mod, security)
        if err != nil {
            err = importErrorf(importPath, "unrecognized import path %q: %v", importPath, err)
        }
    }
    if err != nil {
        rr1, err1 := repoRootFromVCSPaths(importPath, security, vcsPathsAfterDynamic)
        if err1 == nil {
            rr = rr1
            err = nil
        }
    }

所以添加gitlab域到vcsPaths就可以了。 下载go源代码:

vi ./src/cmd/go/internal/vcs/vcs.go    

查看下面的代码:

var vcsPaths = []*vcsPath{
    // GitHub
    {
        pathPrefix: "github.com",
        regexp:     lazyregexp.New(`^(?P<root>github\.com/[A-Za-z0-9_.\-]+/[A-Za-z0-9_.\-]+)(/[A-Za-z0-9_.\-]+)*$`),
        vcs:        "git",
        repo:       "https://{root}",
        check:      noVCSSuffix,
    },

添加代码如下,XXXX Is Your Domain:

    // GitLab
    {
        pathPrefix: "gitlab.xxxx.com",
        regexp:     lazyregexp.New(`^(?P<root>gitlab.xxxx\.com/[A-Za-z0-9_.\-]+/[A-Za-z0-9_.\-]+)(/[A-Za-z0-9_.\-]+)*$`),
        vcs:        "git",
        repo:       "https://{root}",
        check:      noVCSSuffix,
    },

编译和替换go。

你有一个东西要配置。这个例子是基于GitHub的,但这不应该改变这个过程:

$ git config --global url.git@github.com:.insteadOf https://github.com/
$ cat ~/.gitconfig
[url "git@github.com:"]
    insteadOf = https://github.com/
$ go get github.com/private/repo

为了让Go模块工作(使用Go 1.11或更新版本),你还需要设置GOPRIVATE变量,以避免使用公共服务器获取代码:

export GOPRIVATE=github.com/private/repo

看起来像是GitLab的5769期。

在GitLab中,由于存储库总是以.git结尾,我必须在存储库名称的末尾指定.git以使其正常工作,例如: 进口“example.org/myuser/mygorepo.git” 和: $ go get example.org/myuser/mygorepo.git 看起来GitHub通过添加“。git”解决了这个问题。

它应该在“增加对Go的存储库检索的支持”中得到解决。#5958”,前提是正确的元标记就位。 尽管Go本身仍然存在一个问题:“cmd/ Go: Go get无法发现HTML5文档中的元标签”。