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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵