不允许使用内部包装 [英] Use of internal package not allowed
问题描述
我正在尝试构建和运行一个仓库( https://github.com/hyperledger/fabric/tree/master ),但此错误不断弹出,但我仍未找到解决方案.
I'm trying to build and run a repo (https://github.com/hyperledger/fabric/tree/master) but this error keeps popping up and still I haven't found a solution to this.
consensus.go:12:2: use of internal package github.com/hyperledger/fabric/internal/pkg/identity not allowed
这只是出现此错误的许多文件之一. 我很确定我做错了,因为这个仓库应该可以正常工作了.
This is just one of many files that give this error. I'm pretty sure I'm doing something wrong since this repo is suppose to be working.
开始版本:
go version go1.13.5 linux/amd64
OS:Linux Mint 19.2肉桂
OS : Linux Mint 19.2 Cinnamon
推荐答案
内部包(位于路径中具有internal
文件夹的文件夹内的程序包)只能从以internal
文件夹的父级为根的程序包中导入.
Internal packages (packages that are inside a folder that has an internal
folder in their path) can only be imported from packages rooted at the parent of the internal
folder.
例如包pkg/foo/internal/bar
可以由包pkg/foo/internal/baz
导入,也可以从pkg/foo/baz
导入,但不能由包pkg
导入,也不能由pkg/bar
导入.这是设计使然.这么大,可以将复杂的程序包分解成更小的程序包,而不必暴露内部.
E.g. a package pkg/foo/internal/bar
can be imported by the package pkg/foo/internal/baz
and also from pkg/foo/baz
, but cannot be imported by the package pkg
nor can it be imported by pkg/bar
. This is by design. This is so big, complex packages can be broken into smaller packages without having to expose internals.
您必须将内部软件包视为私有"软件包,或者将其从外部"视为不存在.
You have to treat internal packages as "private" or non-existent from the "outside".
请参阅相关内容:我可以在多个源目录中开发go包?
在命令转到:内部目录中了解有关内部软件包的更多信息.
Read more about internal packages at Command go: Internal Directories.
内部软件包是编译器的限制.如果要在自己的项目中公开它们(如果要使用内部软件包),则必须删除internal
文件夹,然后当然也必须更改导入(导入路径).
Internal packages are a compiler restriction. If you want to expose them (if you want to use an internal package) in your own project, you have to remove the internal
folder, and then of course you have to change the imports (import paths) too.
这篇关于不允许使用内部包装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!