为Go包设置一个Mercurial仓库

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

Setting up a Mercurial Repository for Go Packages

问题

我正在努力为Go包设置一个本地的Mercurial仓库。

所有的Mercurial包目录都在以下URL下:

https://server.example.com/go-packages/

我可以通过以下方式克隆一个包:

hg clone https://server.example.com/go-packages/packagename

这个方法可以正常工作。

当我想要使用go命令行安装包时:

go get server.example.com/go-packages/packagename

我会得到以下错误:

package server.example.com/go-packages/packagename: unrecognized import path "server.example.com/go-packages/packagename"

但是当我按照http://golang.org/cmd/go/中的说明进行操作时:

go get server.example.com/go-packages/packagename.hg

它可以完美地工作。

在上述文档中,他们提到了一个<meta>标志。所以我创建了一个包含以下条目的index.html:

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="go-import" content="import-prefix hg repo-root">
        <title>packagename</title>
    </head>
    <body>
        <h1>packagename</h1>
    </body>
</html>

更新:

当我执行wget -O- https://server.example.com/go-packages/packagename/?go-get=1 --no-check-certificate时,我得到:

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="go-import" content="import-prefix hg repo-root">
        <title>packagename</title>
    </head>
    <body>
        <h1>packagename</h1>
    </body>
</html>

更新2:

我发现我的内容是错误的(复制粘贴错误),现在我将其更改为:

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="go-import" content="server.example.com/go-packages/packagename hg https://server.example.com/go-packages/packagename" />
        <title>packagename</title>
    </head>
    <body>
        <h1>packagename</h1>
    </body>
</html>

其中go-packages是包含Mercurial仓库packagename的目录。

但是go get server.example.com/go-packages/packagename仍然无法工作。

英文:

I am struggling to setup a local Mercurial repository for go packages.

All mercurial package directories can are under the following url:

https://server.example.com/go-packages/

I can clone a package via:

hg clone https://server.example.com/go-packages/packagename

That works fine.

When I want to install the package with the go command line:

go get server.example.com/go-packages/packagename

I get the following error:

package server.example.com/go-packages/packagename: unrecognized import path &quot;server.example.com/go-packages/packagename&quot;

But when I do it as explained in http://golang.org/cmd/go/ :

go get server.example.com/go-packages/packagename.hg

It works perfectly.

In the above document they talk about a &lt;meta&gt; flag. So I created a index.html with the following entry:

&lt;html&gt;
    &lt;head&gt;
        &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot; /&gt;
        &lt;meta name=&quot;go-import&quot; content=&quot;import-prefix hg repo-root&quot;&gt;
        &lt;title&gt;packagename&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;h1&gt;packagename&lt;/h1&gt;
    &lt;/body&gt;
&lt;/html&gt;

<h1>Update:</h1>

When I do a wget -O- https://server.example.com/go-packages/packagename/?go-get=1 --no-check-certificate I get:

!DOCTYPE HTML&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot; /&gt;
        &lt;meta name=&quot;go-import&quot; content=&quot;import-prefix hg repo-root&quot;&gt;
        &lt;title&gt;packagename&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;h1&gt;packagename&lt;/h1&gt;
    &lt;/body&gt;
&lt;/html&gt;

<h1>Update 2</h1>
I saw, that my content was wrong (copy paste error) now I changed it to:

&lt;html&gt;
    &lt;head&gt;
        &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot; /&gt;
        &lt;meta name=&quot;go-import&quot; content=&quot;server.example.com/go-packages/packagename hg https://server.example.com/go-packages/packagename&quot; /&gt;
        &lt;title&gt;packagename&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;h1&gt;packagename&lt;/h1&gt;
    &lt;/body&gt;
&lt;/html&gt;

Where go-packages is a directory containing the mercurial repository packagename.

But still go get server.example.com/go-packages/packagename is not working.

答案1

得分: 4

在查看了这个问题(以及附带的代码审查)和这个线程之后:

  • 确保你的“import-prefix hg repo-root”遵循正确的格式
    • import-alias-prefix必须是被“go get”获取的包的前缀或完全匹配。
    • full-repo-root必须是一个包含方案但不包含“.vcs”限定符的仓库的完整URL根。
    • vcs是“git”,“hg”,“svn”等之一。
  • 确保从https://<import>?go-get=1获取的页面确实是你的index.html页面(如果在httpd.conf文件中进行了设置,则不是index.htm或任何其他DirectoryIndex指令)。

> 如果import-alias-prefix与导入不完全匹配,则会执行另一个HTTP获取,获取声明的根(不需要是域的根)。

> 例如,假设“camlistore.org/pkg/blobref”在其HTML头中声明:

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

> ...然后:

> $ go get camlistore.org/pkg/blobref

> ...会查看以下URL:

> https://camlistore.org/pkg/blobref?go-get=1
> http://camlistore.org/pkg/blobref?go-get=1
> https://camlistore.org/?go-get=1
> http://camlistore.org/?go-get=1

> 最终它在根目录(camlistore.org/)找到了相同的go-import

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

> ...然后继续信任它,在磁盘上的导入路径“camlistore.org”处检出git //camlistore.org/r/p/camlistore

英文:

After looking at this issue (and attached code review), and this thread:

  • make sure your "import-prefix hg repo-root" follows the right format
    • The import-alias-prefix must be a prefix or exact match of the
      package being fetched with "go get".
    • The full-repo-root must be a full URL root to a repository containing
      a scheme and not containing a ".vcs" qualifier.
    • The vcs is one of "git", "hg", "svn", etc.
  • make sure the page fetch from https://&lt;import&gt;?go-get=1 is indeed you index.html page (not index.htm or any other DirectoryIndex directive, if this is setup in an httpd.conf file for instance)

> If the import-alias-prefix is not an exact match for the import,
another HTTP fetch is performed, at the declared root (which does
not need to be the domain's root).

> For example, assuming that "camlistore.org/pkg/blobref" declares
in its HTML head:

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

> ... then:

> $ go get camlistore.org/pkg/blobref

> ... looks at the following URLs:

> https://camlistore.org/pkg/blobref?go-get=1
> http://camlistore.org/pkg/blobref?go-get=1
> https://camlistore.org/?go-get=1
> http://camlistore.org/?go-get=1

> Ultimately it finds, at the root (camlistore.org/), the same go-import:

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

> ... and proceeds to trust it, checking out git //camlistore.org/r/p/camlistore
at the import path of "camlistore.org" on disk.

huangapple
  • 本文由 发表于 2012年9月13日 18:21:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/12404109.html
匿名

发表评论

匿名网友

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

确定