当我在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上的第二天,所以这对我来说是神奇的。
发布于 2019-05-24 18:08:46
这很简单,看看它:
$> 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/...时,它会命中该文件,并知道"goa.design/....“必须使用git从https://github.com/goadesign/plugins中检索。
这是一个很好的article
https://stackoverflow.com/questions/56290279
复制相似问题