【问题标题】:How does go know where to get packages fromgo 如何知道从哪里获取包裹
【发布时间】:2019-05-24 09:59:01
【问题描述】:

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

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

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

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

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

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

【问题讨论】:

标签: go go-modules


【解决方案1】:

很简单,看看吧:

$> 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.com/goadesign/plugins 检索“goa.design/...”。

这是一个很好的article

【讨论】:

    猜你喜欢
    • 2020-05-18
    • 1970-01-01
    • 2018-10-03
    • 1970-01-01
    • 1970-01-01
    • 2015-04-10
    • 1970-01-01
    • 2017-12-02
    • 1970-01-01
    相关资源
    最近更新 更多