Make Golang get command compatible with Gitlab

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

What do we got?

Gitlib has released 6.0, claiming to be an enterprise-class version, as the first choice for private git libraries, more and more people use

Suppose there is such a Golang library, the URL is http://git.wendal.net/wendal/gofly

If you try to execute the following statement to get the library,

go get git.wendal.net/wendal/gofly#会输出package git.wendal.net/wendal/gofly: unrecognized import path "git.wendal.net/wendal/gofly"

However, if we enter

go get git.wendal.net/wendal/gofly.git#会输出fatal: repository 'git.wendal.net/wendal/gofly' does not existpackage git.wendal.net/wendal/gofly.git: exit status 128

Why? Seemingly go get does not support custom library addresses AH (git)

And look at the code inside $GOROOT/src/cmd/go/vcs.go.

    // General syntax for any server.    {        re:   `^(?P
  
   
    
   (?P
   
    
     
    ([a-z0-9.\-]+\.)+[a-z0-9.\-]+(:[0-9]+)?/[A-Za-z0-9_.\-/]*?)\.(?P
    
     
      
     bzr|git|hg|svn))(/[A-Za-z0-9_.\-]+)*$`,        ping: true,    },
    
     
   
    
  
   

As you can see, for unknown library addresses (not Github/google code/bitbucket/launchpad), they are set in the configuration here

According to the regular expression above, the input git.wendal.net/wendal/gofly can be obtained

root = git.wendal.net/wendal/goflyrepo = git.wendal.net/wendal/goflyvcs  = git

What? When you use Git for clone, you actually execute the

git clone $repo $GOPATH/src/$root#展开之后(假设GOPATH=/opt/gopath)git clone git.wendal.net/wendal/gofly /opt/gopath/src/git.wendal.net/wendal/gofly

The Git repository address is a local path, so it's not a mistake.

How to solve it? Add a custom library address similar to GitHub

First, copy a github configuration

    // Github    {        prefix: "github.com/",        re:     `^(?P
  
   
    
   github\.com/[A-Za-z0-9_.\-]+/[A-Za-z0-9_.\-]+)(/[A-Za-z0-9_.\-]+)*$`,        vcs:    "git",        repo:   "https://{root}",        check:  noVCSSuffix,    },
  
   

Change into

    // git.xwoods.org    {        prefix: "git.wendal.net/",        re:   `^(?P
  
   
    
   git\.wendal\.net/(?P
  
   

.[A-Za-z0-9_.\-]+/[A-Za-z0-9_.\-]+))(/[A-Za-z0-9_.\-]+)*))$`, ping: false, repo: "git@git.wendal.net:{p}.git", vcs : "git", },

Note that re and repo, do a special deal with Oh, more than a P variable, so that repo will be the standard SSH git address, automatically use the key (haha, private library)

Finally, we need to compile the Golang

# linux/mac 下$GOROOT/src/make.bash#windows下cd %GOROOT%\src\cmd\gogo install

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.