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 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用