go get獲取gitlab私有倉庫的代碼

目錄

1、Gitlab的搭建

  在上一篇文章中,已經介紹瞭如何搭建Gitlab Https服務<Nginx設置Https反向代理,指向Docker Gitlab11.3.9 Https服務>

2、如何通過go get,獲取Gitlab的代碼

  在$GOROOT/src/cmd/go/internal/get/vcs.go的源碼中可以看到,大概在997行左右 ,go get還是使用GIT獲取代碼的。

// vcsPaths defines the meaning of import paths referring to
// commonly-used VCS hosting sites (github.com/user/dir)
// and import paths referring to a fully-qualified importPath
// containing a VCS type (foo.com/repo.git/dir)
var vcsPaths = []*vcsPath{
    // Github
    {
        prefix: "github.com/",
        re:     `^(?P<root>github\.com/[A-Za-z0-9_.\-]+/[A-Za-z0-9_.\-]+)(/[\p{L}0-9_.\-]+)*$`,
        vcs:    "git",
        repo:   "https://{root}",
        check:  noVCSSuffix,
    },

    // Bitbucket
    {
        prefix: "bitbucket.org/",
        re:     `^(?P<root>bitbucket\.org/(?P<bitname>[A-Za-z0-9_.\-]+/[A-Za-z0-9_.\-]+))(/[A-Za-z0-9_.\-]+)*$`,
        repo:   "https://{root}",
        check:  bitbucketVCS,
    },

    // IBM DevOps Services (JazzHub)
    {
        prefix: "hub.jazz.net/git/",
        re:     `^(?P<root>hub\.jazz\.net/git/[a-z0-9]+/[A-Za-z0-9_.\-]+)(/[A-Za-z0-9_.\-]+)*$`,
        vcs:    "git",
        repo:   "https://{root}",
        check:  noVCSSuffix,
    },

    // Git at Apache
    {
        prefix: "git.apache.org/",
        re:     `^(?P<root>git\.apache\.org/[a-z0-9_.\-]+\.git)(/[A-Za-z0-9_.\-]+)*$`,
        vcs:    "git",
        repo:   "https://{root}",
    },

    // Git at OpenStack
    {
        prefix: "git.openstack.org/",
        re:     `^(?P<root>git\.openstack\.org/[A-Za-z0-9_.\-]+/[A-Za-z0-9_.\-]+)(\.git)?(/[A-Za-z0-9_.\-]+)*$`,
        vcs:    "git",
        repo:   "https://{root}",
    },

    // chiselapp.com for fossil
    {
        prefix: "chiselapp.com/",
        re:     `^(?P<root>chiselapp\.com/user/[A-Za-z0-9]+/repository/[A-Za-z0-9_.\-]+)$`,
        vcs:    "fossil",
        repo:   "https://{root}",
    },

    // General syntax for any server.
    // Must be last.
    {
        re:   `^(?P<root>(?P<repo>([a-z0-9.\-]+\.)+[a-z0-9.\-]+(:[0-9]+)?(/~?[A-Za-z0-9_.\-]+)+?)\.(?P<vcs>bzr|fossil|git|hg|svn))(/~?[A-Za-z0-9_.\-]+)*$`,
        ping: true,
    },
}

  如果是 http 服務,可以通過使用-insecure選項獲取:

> go get -insecure  mygitlab.com/user/repo

  但每次要輸入密碼比較麻煩,不過go提供了https->ssh的映射,執行如下命令即可,其中lion是你的帳號:

> git config --global url."[email protected]:".insteadOf "https://[email protected]/"

  配置好的文件在~/.gitconfig文件中,執行cat ~/.gitconfig可以 看到以下內容:

[url "[email protected]:"]
    insteadOf = https://[email protected]/

  獲取後的效果如下:


博文作者:迦壹
博客地址:go get獲取gitlab私有倉庫的代碼
轉載聲明:可以轉載, 但必須以超鏈接形式標明文章原始出處和作者信息及版權聲明,謝謝合作!
  
假設您認爲這篇文章對您有幫助,可以通過以下方式進行捐贈,謝謝!

比特幣地址:1KdgydfKMcFVpicj5w4vyn3T88dwjBst6Y
以太坊地址:0xbB0a92d634D7b9Ac69079ed0e521CC2e0a97c420


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章