如何禁用“不允许使用内部包”错误提示?

huangapple go评论78阅读模式
英文:

How to disable "use of internal package not allowed"

问题

我有一个Go程序,它检查一个大型代码库,选择一些感兴趣的包,然后生成一个新的main.go文件,其中包含以下内容:

import(
  _ (这里是感兴趣的包)
  _ (这里是另一个感兴趣的包)
  ...
)
func main() {...}

main函数对这些包在它们的init方法中设置的一些值感兴趣。

然而,其中一些包具有(...)/internal/(...)路径,因此当尝试运行生成的main.go时,会出现use of internal package not allowed的错误。

是否有一些编译器/链接器/其他标志可以禁用internal路径检查?

英文:

I have a go program that inspects a large repository, selects some packages of interest, and then generates a new main.go file that has:

import(
  _ (package of interest here)
  _ (another package of interest here)
  ...
)
func main() {...}

The main is interested in some values these packages set in their init method.

However some of these packages have (...)/internal/(...) paths and so I get use of internal package not allowed when trying to run the generated main.go.

Is there some compiler / linker / other flag that disables the internal path check?

答案1

得分: 18

如果导入的路径中包含元素"internal",则在导入代码位于"internal"目录的父目录树之外时,将禁止导入。没有例外的机制。特别地,按设计,没有ACL机制允许其他包使用内部包的白名单。

规则提案

英文:

An import of a path containing the element “internal” disallowed if the importing code is outside the tree rooted at the parent of the “internal” directory. There is no mechanism for exceptions. In particular, by design, there is no ACL mechanism for allowing a whitelist of other packages to use an internal package.

Proposal for the rule

huangapple
  • 本文由 发表于 2016年12月9日 20:42:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/41060764.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定