doucan8049 2016-03-22 17:42 采纳率: 100%
浏览 20
已采纳

给定未知的代码托管域网站时,“获取”如何工作?

Let's take an example. The command below will do:

go get robpike.io/ivy

This will get me the content of the repository under $GOPATH/src. Great!

Now, how does it work?

First, robpike.io/ivy replies with a HTTP-redirect:

HTTP/1.1 302 Found

<a href="http://godoc.org/robpike.io/ivy">Found</a>

From reading at go help importpath, I learn that:

If the import path is not a known code hosting site and also lacks a version control qualifier, the go tool attempts to fetch the import over https/http and looks for a tag in the document's HTML

However, looking for a metatag inside the content of the redirected page using:

curl -D --raw https://godoc.org/robpike.io/ivy | grep go-import

returns nothing.

Reading further:

The repo-root is the root of the version control system containing a scheme and not containing a .vcs qualifier.

For example,

import "example.org/pkg/foo"

will result in the following requests:

https://example.org/pkg/foo?go-get=1 (preferred)

http://example.org/pkg/foo?go-get=1 (fallback, only with -insecure)

Again:

curl -D --raw https://robpike.io/ivy?go-get=1

returns nothing.

So the question is: how can I do the same thing as Mr. Rob Pike and use my own site with the go get command?

  • 写回答

2条回答 默认 最新

  • duankuangxie9070 2016-03-22 17:53
    关注

    That last command you entered does return data. When I run curl -D --raw https://robpike.io/ivy\?go-get\=1 in my terminal, I get the following data back:

    <meta name="go-import" content="robpike.io/toy git https://github.com/robpike/toy.git"><meta name="go-import" content="robpike.io/cmd/translate git https://github.com/robpike/translate.git"><meta name="go-import" content="robpike.io/cmd/freq git https://github.com/robpike/freq.git"><meta name="go-import" content="robpike.io/cmd/hira git https://github.com/robpike/hira.git"><meta name="go-import" content="robpike.io/cmd/kana git https://github.com/robpike/kana.git"><meta name="go-import" content="robpike.io/cmd/kata git https://github.com/robpike/kata.git"><meta name="go-import" content="robpike.io/nihongo git https://github.com/robpike/nihongo.git"><meta name="go-import" content="robpike.io/cmd/typo git https://github.com/robpike/typo.git"><meta name="go-import" content="robpike.io/filter git https://github.com/robpike/filter.git"><meta name="go-import" content="robpike.io/cmd/unicode git https://github.com/robpike/unicode.git"><meta name="go-import" content="robpike.io/cmd/doc git https://github.com/robpike/doc.git"><meta name="go-import" content="robpike.io/cmd/scrub git https://github.com/robpike/scrub.git"><meta name="go-import" content="robpike.io/cmd/strings git https://github.com/robpike/strings.git"><meta name="go-import" content="robpike.io/ivy git https://github.com/robpike/ivy.git"><meta name="go-import" content="robpike.io/cmd/now git https://github.com/robpike/now.git">
    

    Ths allows the go get command to resolve the vanity path to git repositories.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用js遍历数据并对非空元素添加css样式
  • ¥15 使用autodl云训练,希望有直接运行的代码(关键词-数据集)
  • ¥50 python写segy数据出错
  • ¥20 关于线性结构的问题:希望能从头到尾完整地帮我改一下,困扰我很久了
  • ¥30 3D多模态医疗数据集-视觉问答
  • ¥20 设计一个二极管稳压值检测电路
  • ¥15 内网办公电脑进行向日葵
  • ¥15 如何输入双曲线的参数a然后画出双曲线?我输入处理函数加上后就没有用了,不知道怎么回事去掉后双曲线可以画出来
  • ¥15 soildworks装配体的尺寸问题
  • ¥100 有偿寻云闪付SDK转URL技术