GitHub的Go支持

huangapple go评论78阅读模式
英文:

Go support for GitHub

问题

在Go语言中,有一个惯例,即如果你创建的项目存储在GitHub上,使用以下文件夹命名方式:

./src/github.com/<user>/<repo>

当我运行go get命令时,Go语言知道如何检出该仓库。

现在我想知道Go语言是否对GitHub有特殊支持(如果有的话,还有哪些支持),或者是否可以使用任何URL(如果可以的话,URL上需要放置什么内容以使其正常工作)。

请问有人可以解答一下吗?

英文:

In Go, there is the practice that if you create a project that is stored on GitHub, to use a folder name that is:

./src/github.com/&lt;user&gt;/&lt;repo&gt;

When I now run go get, Go knows how to check out the repo.

Now I wonder if there is some special support baked in into Go for GitHub (and if so, for what else is this available), or if this works with any URL (and if so, what has to be placed on that URL to make things work).

Can anybody please shed some light onto this?

答案1

得分: 6

是的,go工具原生支持最流行的代码托管站点:

Bitbucket(Git,Mercurial)

import "bitbucket.org/user/project"
import "bitbucket.org/user/project/sub/directory"

GitHub(Git)

import "github.com/user/project"
import "github.com/user/project/sub/directory"

Google Code Project Hosting(Git,Mercurial,Subversion)

import "code.google.com/p/project"
import "code.google.com/p/project/sub/directory"

import "code.google.com/p/project.subrepository"
import "code.google.com/p/project.subrepository/sub/directory"

Launchpad(Bazaar)

import "launchpad.net/project"
import "launchpad.net/project/series"
import "launchpad.net/project/series/sub/directory"

import "launchpad.net/~user/project/branch"
import "launchpad.net/~user/project/branch/sub/directory"

对于未知的站点,你有两个选项-在导入路径中直接指定版本控制系统(VCS)类型:

import "example.org/user/foo.git"

或者准备你的仓库在HTML中包含标签,像这样:

<meta name="go-import" content="example.org git https://code.org/r/p/exproj">

详细信息请参阅go文档(也可以通过go help importpath命令获得,如注释中所述):

http://golang.org/cmd/go/#hdr-Remote_import_paths

英文:

Yes, go tool has support for the most popular code hosting sites out of the box:

Bitbucket (Git, Mercurial)

	import &quot;bitbucket.org/user/project&quot;
	import &quot;bitbucket.org/user/project/sub/directory&quot;

GitHub (Git)

	import &quot;github.com/user/project&quot;
	import &quot;github.com/user/project/sub/directory&quot;

Google Code Project Hosting (Git, Mercurial, Subversion)

	import &quot;code.google.com/p/project&quot;
	import &quot;code.google.com/p/project/sub/directory&quot;

	import &quot;code.google.com/p/project.subrepository&quot;
	import &quot;code.google.com/p/project.subrepository/sub/directory&quot;

Launchpad (Bazaar)

	import &quot;launchpad.net/project&quot;
	import &quot;launchpad.net/project/series&quot;
	import &quot;launchpad.net/project/series/sub/directory&quot;

	import &quot;launchpad.net/~user/project/branch&quot;
	import &quot;launchpad.net/~user/project/branch/sub/directory&quot;

For the unknown sites you have two options - specify VCS type directly in the import path:

import &quot;example.org/user/foo.git&quot;

or prepare your repo to include <meta> tag in HTML, like this:

&lt;meta name=&quot;go-import&quot; content=&quot;example.org git https://code.org/r/p/exproj&quot;&gt;

See go docs for more details, it's thoroughly explained (also available by go help importpath, as stated in comments):

http://golang.org/cmd/go/#hdr-Remote_import_paths

huangapple
  • 本文由 发表于 2014年11月28日 16:19:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/27184517.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定