如何禁用“不允许使用内部包" [英] How to disable "use of internal package not allowed"

查看:37
本文介绍了如何禁用“不允许使用内部包"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 go 程序,它检查一个大型存储库,选择一些感兴趣的包,然后生成一个新的 main.go 文件,该文件具有:

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() {...}

主要对这些包在它们的 init 方法中设置的一些值感兴趣.

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

但是,其中一些包具有 (...)/internal/(...) 路径,因此在尝试运行生成的 main.go 时,我得到 不允许使用内部包.

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?

推荐答案

如果导入代码位于以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.

规则提案

这篇关于如何禁用“不允许使用内部包"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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