英文:
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 "server.example.com/go-packages/packagename"
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 <meta>
flag. So I created a index.html with the following entry:
<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>
<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>
<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>
<h1>Update 2</h1>
I saw, that my content was wrong (copy paste error) now I changed it to:
<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>
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.
- The import-alias-prefix must be a prefix or exact match of the
- make sure the page fetch from
https://<import>?go-get=1
is indeed youindex.html
page (notindex.htm
or any otherDirectoryIndex
directive, if this is setup in anhttpd.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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论