英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论