golang禁用“不允许使用内部软件包” [英] golang disable "use of internal package not allowed"

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

问题描述

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

  import(
_(这里感兴趣的包)
_(这里另一个感兴趣的包)
...

func main ){...}

主要关注这些包在 init 方法。

然而,其中一些包具有(...)/ internal /(...)路径,所以我得到使用内部包当试图运行生成的main.go时允许



是否有一些编译器/链接器/其他标志禁用 internal path check?

解决方案

不允许导入包含元素internal的路径如果导入代码位于以internal目录的父级为根的树之外。没有例外的机制。特别是,通过设计,没有ACL机制允许其他包的白名单使用内部包。

google.com/document/d/1e8kOo3r51b2BWtTs_1uADIA5djfXhPT36s6eHVRIvaU/editrel =nofollow noreferrer>规则提案


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?

解决方案

An import of a path containing the element "internal" is 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

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

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