如何知道从何处获取软件包 [英] How does go know where to get packages from

查看:57
本文介绍了如何知道从何处获取软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在go应用程序中导入软件包时(使用带有golang插件的模块和vscode):

When I import a package in a go application (using modules and vscode with golang plugin):

import (
   cors "goa.design/plugins/cors/dsl"
)

go自动检索软件包.怎么知道从哪里得到它呢?我认为它只是从github.com提取资源,但是该项目的存储库名称中是 https://github.com/goadesign/goa ...如果我将导入更改为:

go automatically retrieves the package. How does go know where to get it from? I figured it simply pulls the sources from github.com, but the repository for this project is at https://github.com/goadesign/goa no . in the name. And if I change the import to:

import (
   cors "goa.design/plugins/v3/cors/dsl"
)

它检索 v3 包.我很乐意RTFM,但不确定我需要阅读哪个FM.

It retrieves the v3 package. I would gladly RTFM, but not sure which FM I need to read.

顺便说一句:这是我第二天去 go ,所以对我来说这是神奇的.

Btw: this is my second day on go so this is magic to me.

推荐答案

很简单,请检查一下:

$> curl https://goa.design/plugins/cors/dsl
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-us">
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">


  <meta name="go-import" content="goa.design/plugins git https://github.com/goadesign/plugins">
  <meta name="go-source" content="goa.design/plugins _ https://github.com/goadesign/plugins/tree/master/{/dir} https://github.com/goadesign/plugins/blob/master{/dir}/{file}#L{line}">

此处的键位于名为"go-import"的标签中.当 go get 请求 https://goa.design/ ...时,它会HTML文件,并知道必须使用git从 https://github中检索到"goa.design/....".com/goadesign/plugins .

The key here is in the tag named "go-import". When go get requests https://goa.design/..., it hits that HTML file and knows that "goa.design/...." must be retrieved using git from https://github.com/goadesign/plugins.

这是一个很好的文章

这篇关于如何知道从何处获取软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆